Simulink and .mat file

조회 수: 4 (최근 30일)
Frederico
Frederico 2011년 2월 27일
I'm trying to use a .mat function to call,run and then analyze a Simulink model.I can call and run, but then when I want to do a math operation to the outuput of Simulink it seems my .mat file can't load the data. I'm using a "save to workspace" block to save the data results from simulink.
Can anyone help me with this? Thanks
  댓글 수: 1
Andreas Goser
Andreas Goser 2011년 2월 27일
From the words, I'd says you mean a MATLAB file, a function or script AKA M-File. MAT files are data files. Please clarify. I will write an answer based on the MATLA file assupmtion.

댓글을 달려면 로그인하십시오.

답변 (2개)

Andreas Goser
Andreas Goser 2011년 2월 27일
The description fits to problems where a user runs simulations with the SIM command through a MATLAB code and wonders where the data ends up.
The To Workspace block writes into the MATLAB base workspace. Depending on hoe you work in MATLAB, you may use a different worksapce and thus don't find the data.
You shold also look at the SIM command and the option to retrieve your simulation results through the command.
  댓글 수: 4
Frederico
Frederico 2011년 2월 27일
I will try you suggestion then I'll give you some feedback.
Frederico
Frederico 2011년 2월 27일
Tried your suggestion on Matlab2008.
This is my code:
simOut=sim(FST7DOF,'Chcomp',1000,'Clcomp',2000,'Chreb',1000,'Clreb',2000,'CHcomp',1000,'CLcomp',2000,'CHreb',1000,'CLreb',2000);
And I get this error:
??? Error using ==> Simout at 1
'model' parameter must be a string.

댓글을 달려면 로그인하십시오.


Paulo Silva
Paulo Silva 2011년 2월 27일
The question has a bunch of errors and there isn't reliable information about what error occurs so I will try to guess:
1. If you just want to perform some math operations to the variable dTireFR in the workspace after the simulation has finished and there's some error message please copy and paste it in your question so we can see exactly what it is and in what line. The code you used is also welcome so we can help you. Now this is a wild guess, you are trying to do some calculations but you don't take into account the size and type of the variable, you could be also typing the name of the variable wrong.
2. In case you want to use functions that you made you must provide it as an argument like this myfunction(dTireFR) Another way but less recommended is to define dTireFR as global in the workspace and functions you want to use that variable. Yet another way, import the variable to your function like this assignin('caller','dTireFR',dTireFR) There are even more ways to do it but please do provide the variable as argument.
  댓글 수: 10
Frederico
Frederico 2011년 2월 28일
OK,so if I wanna operate with more data I suppose I just have to add more output blocks and do what I did with dTireFR, am I right?
What about the error I am getting since the beggining:
??? Error using ==> CallSimulink at 10
annotation does not have a parameter named 'value'.
I could find it is one of the set_param('Constant')...I was trying to figure out if there's any problem with the constant block in my Simulink but it seems everything is OK.Also if I set as comment this specific line (one of the 8 set_param(constant)), the Mat code will run without problems...
Any idea about it?
Paulo Silva
Paulo Silva 2011년 2월 28일
[tout,x,y1,y2,y3...yn] = sim(gcs)
y1 is the variable that gets the data from the first output port
y2 is the variable that gets the data from the second output port
y3 is the variable that gets the data from the third output port
...
yn is the variable that gets the data from the nth output port
set_param('ModelName/ConstantBlockName','Value','2') works for me
set_param('ModelName/ConstantBlockName','value','2') also work good
You might have something wrong with the names, I don't know.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by