Simulink and .mat file
Mostrar comentarios más antiguos
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 comentario
Andreas Goser
el 27 de Feb. de 2011
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.
Respuestas (2)
Andreas Goser
el 27 de Feb. de 2011
0 votos
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 comentarios
Frederico
el 27 de Feb. de 2011
Andreas Goser
el 27 de Feb. de 2011
I personally would resolve this by using the <http://www.mathworks.com/help/toolbox/simulink/slref/sim.html SIM command> instead of set_param...'Start'). SIM returns the simulation output.
Frederico
el 27 de Feb. de 2011
Frederico
el 27 de Feb. de 2011
Paulo Silva
el 27 de Feb. de 2011
0 votos
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 comentarios
Frederico
el 27 de Feb. de 2011
Paulo Silva
el 27 de Feb. de 2011
Before the plot and after sim insert this code:
tout = evalin('base', 'tout');
dTireFR = evalin('base', 'dTireFR');
Paulo Silva
el 27 de Feb. de 2011
Forget my last message, I wasn't paying enough attention, you didn't used the sim function but you should because the sim function can return useful variables to your function. You can also change the simulation settings with simset and change it so it will always save the variables to you function instead of the worksapce
Paulo Silva
el 27 de Feb. de 2011
Instead of set_param(gcs,'SimulationCommand','Start');
use [tout,x,dTireFR] = sim(gcs);
Frederico
el 27 de Feb. de 2011
Paulo Silva
el 27 de Feb. de 2011
Yes I forgot that you need to change the blocks, to workspace replaced by output block, you don't have any data because of the lack of one output block (that was my fault).
Frederico
el 27 de Feb. de 2011
Paulo Silva
el 27 de Feb. de 2011
You are accepting the data into the variable dTireFR, you can change the output block name to dTireFR (just to indicate to the user what's that block for).
Frederico
el 28 de Feb. de 2011
Paulo Silva
el 28 de Feb. de 2011
[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.
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!