Plot to axes from a simulink variable

Hi,
I'm trying to plot a variable from simulink in a axes GUI, and that what's happening:
I put the simulation running trought GUI with this command: [timeVector,stateVector,outputVector] = sim('Sistema_s_Atraso_SelfTuning',tempo_simulacao);
and when the simulation ends the ouput variable 'simout' to appear in my base worspace, due to that i can't plot the resulta in my GUI axes. I'm using a variable block in simulink, to get all the data to worspace. The only way that i found to get a variable in base workspace, is to run the simulation manualy in simulink.
what can i do to read the output variable and pot in a GUI axes?
Thanks
Nuno

2 comentarios

TAB
TAB el 30 de En. de 2012
[I'm using a variable block in simulink]. What is "variable block" ?
Have you tried "ToWorkSpace" block?
You are runnung model manually or using "sim()" command, it dosn't make any difference in simulation output.
Nuno Agualusa
Nuno Agualusa el 30 de En. de 2012
yes, it's a "ToWorkSpace" block, called "simout". i'm using the "sim()" command to start the simulation.
My objective is to get the data to plot in a axes GUI after simulation stops.
Thanks
Nuno

Iniciar sesión para comentar.

Respuestas (1)

Kaustubha Govind
Kaustubha Govind el 31 de En. de 2012
Try
sim('Sistema_s_Atraso_SelfTuning',tempo_simulacao, 'DstWorkspace', 'current');
This ensures that all variables created by Simulink use the current workspace as the destination.
EDIT:
The command needs to be:
opts = simset('DstWorkspace', 'current');
sim('Sistema_s_Atraso_SelfTuning',tempo_simulacao, opts);

5 comentarios

Nuno Agualusa
Nuno Agualusa el 31 de En. de 2012
Hi Kaustubha,
Thank you very much for your answer, but the code you gave me doesn't work:
??? Error using ==> INTERFACE_FINAL>run_Callback at 320
The "OPTIONS" parameter must be a structure created by SIMSET.
My problem is not start running simulink from GUI, my problem is when i start the simulation from GUI the variable in simulink 'simout' don't appear in my base workspace, so i can't plot it in a axes. The variable 'simout' is a ToWorkspace block.
But otherwise when i start running the simulation manually from simulink, the variable 'simout' appear in my base worspace, like a 1x1 struct.
I hope i have been clear.
Thank you very much for your time.
Nuno
Kaustubha Govind
Kaustubha Govind el 31 de En. de 2012
Nuno: Yes, your problem is clear to me. The problem is that Simulink creates the 'simout' variable in the base workspace by default. To verify this, use "simout = evalin('base', 'simout');" after the SIM command - this will copy the variable from the base workspace to the GUI function workspace and make it available for plotting. Try:
opts = simset('DstWorkspace', 'current');
sim('Sistema_s_Atraso_SelfTuning',tempo_simulacao, opts);
Nuno Agualusa
Nuno Agualusa el 1 de Feb. de 2012
Still the same Kaustubha. The only way to create the variable 'simout' in workspace is start manually the simulink system, if i start the simulink system trought out GUIDE it doesn't work.
Here is the code that i'm using:
function run_Callback(hObject, eventdata, handles)
% hObject handle to run (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[tempo_simulacao]=evalin('base','tempo_sim');
opts = simset('DstWorkspace', 'current');
[timeVector,stateVector,outputVector]=sim('Sistema_s_Atraso_SelfTuning',tempo_simulacao, opts);
simout = evalin('base', 'simout');
guidata(hObject, handles);
Thank you very much.
Nuno
Kaustubha Govind
Kaustubha Govind el 1 de Feb. de 2012
You only need EITHER "opts = simset('DstWorkspace', 'current');" OR "simout = evalin('base', 'simout');" - not both. Using the first will cause an error in the second statement, because there is no simout variable created in the base workspace in that case.
Nuno Agualusa
Nuno Agualusa el 1 de Feb. de 2012
It didn't work too. I don't know what to do more to solve this situation.
If you don't mind i could send to you my files just to look to them and see if i'm doing somethink wrong in other place.
Thank you very much.
Nuno

Iniciar sesión para comentar.

Categorías

Productos

Preguntada:

el 30 de En. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by