Clear Filters
Clear Filters

Surf plot 3D like the simulation manager

4 views (last 30 days)
youjarr on 1 Jun 2021
Edited: Alvaro on 29 Nov 2022
Hey guys,
I would like to perform the surf plot with the data which results from the simulation manger calculations.
I want to perform it automatically so it can be generated automatically after the simulations.
But somehow I´m not formatting the data right for the surf plot.
After the simulation manager is finished the "out" data is generated and the "in" data for the inut for parsim.
After the simulation i use following code to generate my data:
for i = numSims_Slope:-1:1
for j = numSims_Tilt:-1:1
simOut = out(i,j);
Phi_door_TimeSeries = simOut.logsout.get('Theta_Door_Sensor_deg').Values;
Tilt_Angle_TimeSeries = simOut.logsout.get('Tilt_Angle_Sig').Values;
Slope_Angle_TimeSeries = simOut.logsout.get('Slope_Angle_Sig').Values;
T_m_TimeSeries = simOut.logsout.get('T_m_Mot_HOLD').Values;
Tilt_Angle_Data{i,j} = simOut.logsout.get('Tilt_Angle_Sig').Values.Data;
Slope_Angle_Data{i,j} = simOut.logsout.get('Slope_Angle_Sig').Values.Data;
Phi_door_Data{i,j} = simOut.logsout.get('Theta_Door_Sensor_deg').Values.Data;
T_m_Data{i,j} = simOut.logsout.get('T_m_Mot_HOLD').Values.Data;
This produces me following data (e.g.):
  • Phi_door_Data [19x19] cell
  • T_m_Data [19x19] cell
which is my Z data.
The Tilt_Angle_Data and Slope_Angle_Data are my X and Y Data. I thought if I would log the data it would be easier to generate the plot.
But it seems I only need the data like below written in the code.
This generates me:
  • Angle_Tilt [1x19] double
  • Angle_Slope [1x19] double
  • numSim_OverAll [19x19]
But it is also available in this format because it is the input for the parsim:
Angle_Tilt = (-18:2:18);
Angle_Slope = (-18:2:18);
numSims_Tilt = length(Angle_Tilt);
numSims_Slope = length(Angle_Slope);
numSim_OverAll = numSims_Slope*numSims_Tilt;
for i = 1:numSims_Slope
for j = 1:numSims_Tilt
in(i,j) = Simulink.SimulationInput(mdl);
in(i,j) = setBlockParameter(in(i), [mdl '/PDM/D/TTS/Angle_Slope'], 'Value', num2str(Angle_Slope(i)));
in(i,j) = setBlockParameter(in(i), [mdl '/PDM/D/TTS/Tilt_Slope']'], 'Value', num2str(Angle_Tilt(j)));
I think I just have a simple logic error.
I hope you can help me. Thanks in advance.
Best regards.

Answers (1)

Alvaro on 29 Nov 2022
Edited: Alvaro on 29 Nov 2022
In MATLAB R2022b, if you are using the Simulation Manager, then there is already an incorporated function to generate a surface plot. See the section named 'Plot results' in the following documentation.
For some additional intuition of how the data may be formatted, you can take a look at the following example (see the attached parTestModel.slx).
[Xgrid,Ygrid] = meshgrid(1:0.5:5,1:5);
Zgrid = sin(Xgrid) + cos(Ygrid);
tracker = 1;
for i = 1:size(Xgrid,1)
for j = 1:size(Xgrid,2)
in(tracker) = Simulink.SimulationInput('parTestModel');
in(tracker) = in(tracker).setVariable('X',Xgrid(i,j));
in(tracker) = in(tracker).setVariable('Y',Ygrid(i,j));
in(tracker) = in(tracker).setVariable('Z',Zgrid(i,j));
tracker = tracker + 1;
outs = parsim(in, 'ShowSimulationManager','on');
This is just passing a grid and some data into the Simulink model and outputting it back up. On the top of the manager under the 'Results' tab you can click 'surf' and then set the axes to be the corresponding data that you wish to plot.




Community Treasure Hunt

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

Start Hunting!