How to convert matlab file into a voltage signal in simulink

Hi, I have a code where it is a sin wave for first 0.6 seconds and 0 for the next 0.4 seconds. Which i have created using if statements etc. so its a matlab file. Now thing is i want to generate this as a voltage supply, how do i import this matlab file into the voltage supply. I know there is a 'from workspace' and 'from file' function. but i have no idea how to use this. thanks.

 Akzeptierte Antwort

Orion
Orion am 18 Dez. 2014

1 Stimme

And here comes the debug problems :).
so what you need to do is :

6 Kommentare

Thanks a lot, can i connect the interpreted matlab function straight to a volage source of a say for e.g.: an rc circuit, which is wat i need it for...
No. same answer than the previous post.
You can't connect a simulink block to a simscape block, you need to use the PS-S converter.
I know u have helped me a lot, can u show me how to do this? Is it possible?
I don't have simscape anymore, but I told you the way to do it.
OK i got it
Fine, so you can close this question.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (4)

Orion
Orion am 18 Dez. 2014

1 Stimme

I already answered you in your previous post, it's a best practice to do it directly with Simulink blocks.
But if you insist to use directly an external mfile, you need to use another block : interpreted matlab function

3 Kommentare

Saurabh Sakpal
Saurabh Sakpal am 18 Dez. 2014
Bearbeitet: Saurabh Sakpal am 18 Dez. 2014
Sorry i know, thing is i want it to be a file as it is quicker like if i wan an change something i can just go and change the code instead of move blocks around and chop and change etc.
AND ALSO, why do u say this is 'best practice'?
Orion
Orion am 18 Dez. 2014
Bearbeitet: Orion am 18 Dez. 2014
And best practice, because calling external files often creates some debugging problems.
also does that matlab file have to be a function or a file? And also do i have to specify the time during which it ran in that function? What do i put into the integrated maths function aargh i am so confused? can u show me how to do it?
heres my code
t = 0:0.05:1; %#ok<*NBRAK> a = size(t);
y = zeros(1,a);
i=1; for t = 0:0.05:1
if t<0.6
y(i) = sin(t);
elseif t >= 0.6
y(i)=0;
end
i = i+1;
end
much appreciated

Melden Sie sich an, um zu kommentieren.

Saurabh Sakpal
Saurabh Sakpal am 18 Dez. 2014

0 Stimmen

OK with ps-s converter i have got theres a circle on end, and an arrow on another. the circle doesn't seem to connect to anything….the arrow does….., so i just connect the arrow to the voltage supply, and then ground that the voltage supply, as i can't connect when its in a closed circuit, as it is closed….
Saurabh Sakpal
Saurabh Sakpal am 18 Dez. 2014

0 Stimmen

Thanks again for your help. Appreciate it.
Saurabh Sakpal
Saurabh Sakpal am 19 Dez. 2014

0 Stimmen

Hey its me again, with regards to the PS converter, i have found something else called controlled voltage source. can this work as a replacement?

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by