MATLAB Answers

0

how can i import data from mat file to simulink?

Najmeh Eskandari さんによって質問されました 2018 年 11 月 4 日
最新アクティビティ Najmeh Eskandari さんによって 編集されました 2018 年 11 月 5 日
Hello. I have a simple simulation: a matlab function block, clock(t as an input),scope and a from file block. acos [variable name] is saved in a.mat and in fcn y=acos=cos(t). how can I import acos variable to fcn block? should I define from file block as an input of fcn or..? the photo of simulation is attached.

  0 件のコメント

サインイン to comment.

1 件の回答

Stephan
回答者: Stephan
2018 年 11 月 4 日
編集済み: Stephan
2018 年 11 月 4 日

Hi,
the content in your .mat-file has to be saved as a timeseries object. See this example how to create this.
Your function has to take as many input arguments as signals you want to connect in your model:
.
function y = fcn(u,t)
y = 3*cos(u*t);
end
If you want to pass time and data from .mat-file, change your funtion the way shown in the above example. If your function is defined in this way you can connect both signals in Simulink:
.
But be careful - See the result of this:
.
This is the result, due to the input is a timeseries - the time information is in the .mat-file. I attached a .matfile as example which contains a timeseries object for t=0...10 in 100 steps and the data is from -2*pi...2*pi in 100 steps. See what happens if we diconnect t and change the function to:
function y = fcn(u)
y = 3*cos(u);
end
.
The model now:
.
So think about if you really need the time block for your model. Test the attached model.
Best regards
Stephan

  1 件のコメント

Najmeh Eskandari 2018 年 11 月 5 日
Thanks. I used this simple example to learn more about from file block. in the main simulation I have ur10_dynamic equation.m file that C,G,D matrices are stored as ur10.mat file and I want to use them in impedance2.slx simulation in impedance controller block. (C,G and D are functions of Theta1..6). how can I load them in different lines of program in the impedance controller block and calculate them for Theta1...6?(Theta1..6 are functions of t and we should use clock).

サインイン to comment.



Translated by