Is there a way to link plots to simscape log data / simscape results explorer data?
Show older comments
When you enable data logging for simscape, you can browse all simulation data using the simscape results explorer.
After selecting sveral data nodes, it is possible to "extract current plot into new figure window". I would like to customize my figure and link it to the simulation data but cannot figure out how.

Simlog won't show up as data source and there is also no auto-linking in the data source dialogue.
Any idea or help?
Accepted Answer
More Answers (1)
Yifeng Tang
on 10 Jun 2021
0 votes
You may access everything in simlog through MATLAB base workspace. Follow the instructions on the following documentation page and you will be able to use commands like "plot" and all of its options to customize your figures. You probably will end up with a post-process script once you figure out what you want to plot.
6 Comments
Andreas
on 10 Jun 2021
Yifeng Tang
on 10 Jun 2021
You can extract the time and value (in any reasonable unit you wish) of a simlog signal series, and use them as base workspace variables. Then you can "hold on" and plot several of them together.
Here is the doc page on the "series" of simlog data: https://www.mathworks.com/help/physmod/simscape/ref/simscape.logging.series.html
The "time" and "values" functions/methods of the series will give you the access you need.
Some pseudo-code:
% run some simulation first
t = time(simlog.motor.w.series); % all signal should have the same time stamps
v1 = values(simlog.motor.w.series,'rpm'); % specify unit
v2 = values(simlog.motor.v.series); % default unit
figure(1); clf;
hold on;
plot(t,v1);
plot(t,v2);
I believe you can also do
t = simlog.motor.w.series.time;
v1 = simlog.motor.w.series.values('rpm')
Andreas
on 10 Jun 2021
Yifeng Tang
on 10 Jun 2021
done. thanks for the suggestion.
Yifeng Tang
on 10 Jun 2021
@Andreas Once you know what you want to plot, it's usually easy to write a MATLAB script to access and plot a set of data, with (nearly) unlimited control of how the figure should appear. If you wish for the figure to update automatically after each run, you may put the script name in the Callback function after the simulation is finished (StopFcn). Every time a simulation is finished, the script will be executed and your plot should be updated (or generate a new one, if you like).
Here you can find more info on Model Callbacks: https://www.mathworks.com/help/simulink/ug/model-callbacks.html#btoznm0
Categories
Find more on Variable Initialization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
