MATLAB Answers

0

Simulink From Workspace Block

Asked by Nuh Metehan on 5 Feb 2014
Latest activity Commented on by Azzi Abdelmalek
on 5 Feb 2014
Hello I need a help,
I would like to define a Simulink input which is Sample time dependent.
For an instance; I defined a time variable-function in matlab editor and want to get values at each time step at Simulink input gate.. So i am a little bit confused how to determine this block in simulink. I think i need to used from workspace block but how to express variables ?
Can someone answer in a detailed way ?

  0 Comments

Sign in to comment.

1 Answer

Answer by Azzi Abdelmalek
on 5 Feb 2014
Edited by Azzi Abdelmalek
on 5 Feb 2014

Example with from file block
ts=1 % your sample time
t=0:ts:100*ts % your time vector
y=sin(t) % your signal
ty=[t;y];
save FileName ty % FileName is the name of your mat-file where your signal will be saved
In Simulink set the file name to: FileName
If you want to use a from workspace block, create a variable
ts=1 % your sample time
t=0:ts:100*ts % your time vector
y=sin(t) % your signal
ty=[t;y];
ty=ty'
Then set the variable name in your block to ty and a sample time to ts.
You can also define your variable as a timeseries with from workspace block
N = 100; % number of samples
Ts = 1; % sample time
t = ((0:N)* Ts)'; % time vector
y = sin(t); % your signal
your_signal = timeseries(y,t)
Then set a variable name in your block to your_signal

  1 Comment

Nuh commented
Thanx it was really helpful ;))

Sign in to comment.