How do I plot Simulink signal values saved to the MATLAB workspace on an axes?

I have to plot a signals in a MATLAB gui.
With Simulink I make a simulation and I save the signal in the workspace. I want to plot that signal in a gui axes but I dont know what I have to do.

 Akzeptierte Antwort

I assume you run the Simulink model from the MATLAB GUI using the sim command. The data from your Scope will end up in the GUI (caller) workspace rather than the base workspace. So you should be able to plot it using something like:
plot(ScopeData.time, ScopeData.signals.values)
You may need to specify the handle of the axis on which to plot the data.
Also have a look at this technical solution.
HTH,
Arnaud

5 Kommentare

i run the simulation in simulink, it's necesary to run it from gui??
No, it isn't, but you indicated that you want to plot the signals in the MATLAB GUI, so I logically assume that you wanted to run the Simulink model from the GUI as well. It does have the advantage that the data will be readily available in the GUI workspace rather than the base workspace.
thank you so much!
Thanks, worked. BUT How to draw a realtime?
Real time? When you run simulink, it executes the signals and blocks, with a 'To workspace' block you can save the real time data to MATLAB workspace and then plot it wherever you want.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (7)

Walter Roberson
Walter Roberson am 31 Mai 2011
Are you using a "To Workspace" block? If so then when you look at the variable, what class() and size() is it? And what kind of plot are you thinking of?

6 Kommentare

to save the data i use a option in the scope (save data to workspace) the format is a structure with time. in the workspace appears a structure and inside there are three fields: time, signals(<1x1 struct>, blockName.
I want to plot the signal in time
Do you want to plot the data after the simulation has finished or while it's running? The former is easy, the latter more difficult.
i want to plot after finished
Use the command that Amaud Miege gave above.
plot(ScopeData.time, ScopeData.signals.values)
Though before that you might need to add
ScopeData = evalin('base', ScopeData);
in order to import the data from the base workspace in to the workspace of the current function.
thank you so much!

Melden Sie sich an, um zu kommentieren.

Nuno Agualusa
Nuno Agualusa am 28 Jan. 2012
Hi,
I'm facing the same problem, but with a small diference. I'm running the simulink from GUI, but when the simulation finish doesn't apear a variable 'simout' in my base workspace. So i can´t plot the result on 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 solve this situation?
Thank you very much.
Nuno

2 Kommentare

How are you running the SIM command? You might want to set 'DstWorkspace' to 'current' to make sure that Simulink uses your GUI function workspace as the destination workspace.
yes, the running command that i used is:
[tempo_simulacao]=evalin('base','tempo_sim');
[timeVector,stateVector,outputVector]=sim('Sistema_s_Atraso_SelfTuning',tempo_simulacao);
The problem is when a simulation ends i can't plot in my GUI axes the result of the simulation..and this action has to be peformed only trought out GUI.

Melden Sie sich an, um zu kommentieren.

erhan
erhan am 30 Nov. 2013
I want set guı axes from scope value. Can you give example ?
yati j
yati j am 9 Okt. 2016
Bearbeitet: Walter Roberson am 9 Okt. 2016
Hello, Could u suggest me any tutorial or any solution to this
  • i have my motor dc to run
  • when the dc motor run/rotate, maybe a graph pop-up which is read my motor speed or relevant to the rotation
  • i dont know the connection btween component
  • i dont know how to draw the simulink
i've read and watched a lot of tutorial.
Thank You.
tran xuanminh
tran xuanminh am 26 Jul. 2017
Bearbeitet: Walter Roberson am 26 Jul. 2017
>>plot(ScopeData.time,ScopeData.signals.values);
>>grid on;
??? >>plot(ScopeData.time,ScopeData.signals.values);
|
Error: Unexpected MATLAB operator.
please coment my erro, thanks

3 Kommentare

Change your code to
plot(ScopeData.time,ScopeData.signals.values);
grid on;
how to use plot when each signal value has 3 dimesions ,plot style [1,1,1].
use this for plotting dimension 1 of signal will work:
plot(ScopeData.time,ScopeData.signals.values(1,:));
or maybe this (I can't remmember):
plot(ScopeData.time,ScopeData.signals.values(:,1));
for dimension 2,3 of signal, simply use 2,3 instead of 1.

Melden Sie sich an, um zu kommentieren.

Mohammad Ali Sharifian
Mohammad Ali Sharifian am 4 Apr. 2024
Bearbeitet: Mohammad Ali Sharifian am 4 Apr. 2024
If you are working on a simulink file then using m-file codes for plotting is not a good idea. I recommend pasting your m-file codes in simulink at: model properties>callbacks>stop fcn
This way when you run your simulink, the results will be plotted automatically. see plotting codes here:
Jasmine Poppick
Jasmine Poppick am 26 Apr. 2024
Starting in R2024a, you can use App Designer to interactively create an app for a Simulink model, which includes the capability to easily and performantly visualize signal data in the app using the new time scope UI component.
In addition, you can:
  • Add UI components configured specifically to interact with your model, such as a simulation start/stop control and a simulation progress bar.
  • Tune model variables from the app while the simulation runs by connecting UI components to variables.
For more information, see Create App for Simulink Model.

Kategorien

Mehr zu General Applications finden Sie in Hilfe-Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by