How to get matlab codes into Simulink ??
2 views (last 30 days)
Show older comments
Biprasish Singha
on 30 Sep 2015
Commented: Walter Roberson
on 5 Oct 2015
The following code has been written by me and it is giving my result in Matlab. Can you tell how to use this code in Simulink so that I can give this as input to my switch.??
numpulses=10;
Pcell=cell(1,numpulses);
dt=.000000001;
for i=1:numpulses
T=.00000383*randn+.00000526;
W=2*T/3;
t=0:dt:T;
Pcell{i}=(t<=W);
end
pulse=[Pcell{:}];
t=(0:length(pulse)-1)*dt;
plot(t,pulse) ;
ylim([-1 2])
end
0 Comments
Accepted Answer
Walter Roberson
on 30 Sep 2015
You can use a MATLAB Function Block.
It looks to me as if you would be wanting one value to be available per timestep, rather than wanting all the value to be available at the same time. See http://blogs.mathworks.com/seth/2012/02/09/using-discrete-data-as-an-input-to-your-simulink-model/
5 Comments
Walter Roberson
on 5 Oct 2015
You would not add anything to this code. From Workspace is for the case where you have created data somehow as a MATLAB variable and want to import it to Simulink. For example after calculating your variable "pulse" you might want to make it available to Simulink.
From Workspace reads the data from the workspace of the function that Simulink was started from if you use the sim() command. If you start a Simulink model from the graphics menu, then From Workspace will read data from the 'base' workspace. You can push data into the base workspace from MATLAB by using assignin('base'), such as
assignin('base', 'pulse', pulse);
More Answers (0)
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!