Clear Filters
Clear Filters

Plotting SimScape simlog Simulation data via Script

4 views (last 30 days)
Hi,
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.
Thanks
% Generate simulation results if they don't exist
if ~exist('simlog_Pneumatic_SingleActing', 'var')
sim('Pneumatic_SingleActing')
end
% 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');
end
figure(h2_Pneumatic_SingleActing)
clf(h2_Pneumatic_SingleActing)
plotPressureTemperatureVolume(simlog_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')
end
  2 Comments
Vasco Lenzi
Vasco Lenzi on 10 Sep 2020
The first thing I see is that you wrote "Convertor" in the script but is Converter in the model.
Try to write a dot (.) after simlog in the command window, then press TAB. You will get a list of all the component within simlog. You can then find the right variable adress and use it in your script.
>>simlog.
and then TAB, pick he right field from the column, then again TAB and navigate until your desired values.
PB75
PB75 on 14 Sep 2020
Hi Vasco,
Thanks for your reply, the below code works and opens up the data tree of simlog data.
simlog_Pneumatic_SingleActing.print

Sign in to comment.

Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!