Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Can I display the simulink scope in a GUI?

Asked by Gustavo Amorim on 6 Sep 2012

I'm designing a GUI that calculate PID parameters, this GUI passes the Kp, Ki, Kd parameters to PID Controller on simulink and then simulate it. I'd like to display the scope of simulation (scope block) in a GUI window. How could I do it?


Gustavo Amorim



2 Answers

Answer by TAB on 6 Sep 2012

Log your data coming in the simulink scope to base workspace and plot the data in your gui after simulation.

To enable the scope data logging double click on scope, go to "Scope parameters --> History" and select "Save data to workspace". Structure with time is the best suitable format for data logging.

Now after simulation, scope data will be save in the base workspace.

To plot the data



Gustavo Amorim on 22 Sep 2012

Thanks for answering TAB, in this case I'll add an axes to my GUI and use

plot(ScopeData.time,ScopeData.signals.values) as a function callback, right?

TAB on 22 Sep 2012

You can use a button to plot the data after simulation. In the button's callback you can use the plot command.

Just for check, after the simulation, call plot command from your workspace. It opens a new figure with graph plotted on it.

Answer by Craig on 6 Sep 2012

I've made a similar script for optimising parameters in a Simulink model. If one uses the sim(model) in the GUI's script, by default this returns some variable yout of simulation results, the first row being timestep - as you probably know.

Then one could use setappdata and getappdata to transfer the data between callbacks.

You'll need a Axes window in the GUI (easiest to do in GUIDE). In r2007b to get the data to plot I needed to add variables to the GUI handle. For me

handles.variabletoplot = variabletoplot

seemed to work but I'll admit my understanding is fuzzy on this. You can use


to set the 'current' GUI axes handle for any succeeding plot commands, such as :



Gustavo Amorim on 22 Sep 2012

Hey Craig, thanks for answering, I tried to do what you said, but nothing happened, the Axes window didn't updated with the scope data. I used:

handles.ScopeData = ScopeData;


Is that right?

Craig on 24 Sep 2012

the second line should be referring to an axes handle e.g. axes3


Contact us