Plotting SimScape simlog Simulation data via Script

7 views (last 30 days)
Using SimScape for my pnuematic actuator model.
Logging data via simlog and then looking to export and plot the simulation results via a matlab script.
Using an existing template i found from another ssc model, however the channel names are different, encountering errors with correct naming of the data to export.
Model name is "Pneumatic_SingleActing" and simlog data is "simlog_Pneumatic_SingleActing"
Looking to export data from the Translational Mechanical Convertor (G)
  • Translational Mechanical Convertor (G).A.T
  • Translational Mechanical Convertor (G).A.p
  • Translational Mechanical Convertor (G).volume
Any help be great in editing the code to export the variables such as translator, temp, pressure and volume.
% Generate simulation results if they don't exist
if ~exist('simlog_Pneumatic_SingleActing', 'var')
% Reuse figure if it exists, else create new figure
if ~exist('h2_Pneumatic_SingleActing', 'var') || ...
~isgraphics(h2_Pneumatic_SingleActing, 'figure')
h2_Pneumatic_SingleActing = figure('Name', 'Pneumatic_SingleActing');
% Create plot from simulation results
function plotPressureTemperatureVolume(simlog)
% Get simulation results
t = simlog.Translational_Mechanical_Convertor.A.p.series.time;
p_A = simlog.Translational_Mechanical_Convertor.A.p.series.values('MPa');
T_A = simlog.Translational_Mechanical_Convertor.A.T.series.values('K');
V_A = simlog.Translational_Mechanical_Convertor.volume.series.values('m^3');
% Plot results
handles(1) = subplot(3, 1, 1);
plot(t, p_A, 'LineWidth', 1)
hold off
grid on
ylabel('Pressure (MPa)')
title('Actuator Pressure and Temperature')
handles(2) = subplot(3, 1, 2);
plot(t, T_A, 'LineWidth', 1)
hold off
grid on
ylabel('Temperature (K)')
xlabel('Time (s)')
legend('Chamber A', 'Location', 'Best')
handles(2) = subplot(3, 1, 3);
plot(t, V_A, 'LineWidth', 1)
hold off
grid on
ylabel('Volume (m^3)')
xlabel('Time (s)')
legend('Chamber A', 'Volume', 'Best')
linkaxes(handles, 'x')
PB75 on 14 Sep 2020
Hi Vasco,
Thanks for your reply, the below code works and opens up the data tree of simlog data.

Sign in to comment.

Answers (0)


Find more on Foundation and Custom Domains 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!