Moving Simulink Data Into the workspace

I am Running a Simulink Model From my GUI and i would like data from to the workspace bloacks to end up in the Matlab Workspace so i can anaylse it afterwards. The data will aperar their if i run it manually but running it through the GUI it does not appear at all.
What comand do i need to use to do this ? And which part of my GUI should i place it in .

1 Kommentar

Paul
Paul am 29 Mär. 2012
I have tried using the Assign function with no luck
assignin('base','helicopter_target_b', 'helicopter_target');
assignin('base',' Ctrlout_b', 'Ctrlout');
assignin('base','Heliout_b', 'Heliout');
the third variables are the names of my to workspace blocks

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Kaustubha Govind
Kaustubha Govind am 29 Mär. 2012

6 Stimmen

Assuming that you're using the SIM command to run the model from your GUI, you need to set the SrcWorkspace and DstWorkspace options to specify which workspaces you want Simulink to use as the source and destination workspace. By default, the variables are created in the "current" workspace, which would be the workspace of your GUI callback function. To force Simulink to always read/write to the base workspace, use:
options=simset('SrcWorkspace','base','DstWorkspace','base');
sim('mymdl',[0 duration],options)

4 Kommentare

Paul
Paul am 29 Mär. 2012
Thank you . This makes more sense than anything i have been trying
so am i right in thinking if i want the sim to run indefiatly. running using the gui and sending the data to the matlab workspace i need to do
(my sim is called manual flight)
options=simset(('SrcWorkspace','caller','DstWorkspace','base');
sim(manualflight,options)
Paul
Paul am 29 Mär. 2012
When i try different variations . I get this error message
??? Error using ==> guimanualflight>Start_Callback at 304
'DstWorkspace' parameter is not supported in this form of syntax for sim command.
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> guimanualflight at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)guimanualflight('Start_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Kaustubha Govind
Kaustubha Govind am 30 Mär. 2012
SrcWorkspace needs to be 'current', not 'caller'. Also, the SIM command takes the model name in the form a string.
You can try:
options=simset(('SrcWorkspace','current','DstWorkspace','base');
sim('manualflight', [0 Inf], options);
If that still doesn't work, run "docsearch DstWorkspace" and see if you find examples in the documentation. There was some change in the syntax of the SIM command recently, so it could be that you are using an older version that doesn't support the form of syntax I wrote.
Paul
Paul am 10 Apr. 2012
Thankyou this works perfectly

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

TAB
TAB am 30 Mär. 2012

1 Stimme

Variables from 'To Workspace' block are saved in calling-workspace. Your way of saving them to 'base-Workspace is correct. Just make correction in assignin() call. Assign the variable values, not string.
assignin('base','helicopter_target_b', helicopter_target);
assignin('base','Ctrlout_b', Ctrlout);
assignin('base','Heliout_b', Heliout);

1 Kommentar

Paul
Paul am 10 Apr. 2012
This seems to not work . when I run the simulation is says that the variables have not been defined
May this be a problem from runing it from a GUI

Melden Sie sich an, um zu kommentieren.

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by