How can I add an XYplot to Simulink Data Inspector programmatically ?

2 vues (au cours des 30 derniers jours)
Pavan
Pavan le 26 Août 2023
Réponse apportée : Ashok le 17 Sep 2024
I make extensive use of plotOnSubPlot to programmatically generate views in SDI. Is there a way to do that with XY type plots 'programmatically' ? It looks like a pretty straightforward functionality by extension. But I cant seem to find any documentation for the same. Please help me see a better way than manually expanding trees and selecting signals in drop down boxes.
  2 commentaires
Mike
Mike le 3 Nov 2023
Did you find a work around for this?
Pavan
Pavan le 3 Nov 2023
Modifié(e) : Pavan le 3 Nov 2023
Nope. Maybe more votes on this would let Mathworks know that this is something on their users' want list.

Connectez-vous pour commenter.

Réponses (1)

Ashok
Ashok le 17 Sep 2024
Hello Pavan,
I comprehend that you are trying to plot XY data from MATLAB on the “Simulink Data Inspector”. There are couple of ways you can achieve the same, depending on the desired level of control over the subplot axes.
1. The first option is the “Simulink.sdi.plot” function. This function enables the user to quickly create plots on the “Simulink Data Inspector”. You can refer to the following link for more information.
For instance, the following code plots sine waves of different frequencies on the “Simulink Data Inspector”.
% Generating dummy XY data
time = 0:0.1:10;
sin1 = sin(time);
sin2 = sin(2*time);
sin3 = sin(3*time);
%% Basic plot on the SDI
Simulink.sdi.plot([sin1; sin2; sin3],time);
2. In case additional control is required over the subplot axes, one can first create “Simulink.sdi.Run” and “Simulink.sdi.Signal” objects from the XY data in MATLAB. The created objects can then be placed inside the appropriate subplots using the “plotOnSubPlot” command. The following snippet demonstrates the same.
%% Plotting on SDI with better axes control
% Setting the SDI subplot layout
Simulink.sdi.setSubPlotLayout(3,1);
% Creating timeseries data from XY data
sin1_ts = timeseries(sin1,time);
sin2_ts = timeseries(sin2,time);
sin3_ts = timeseries(sin3,time);
sin1_ts.Name = "sin f=1";
sin2_ts.Name = "sin f=2";
sin3_ts.Name = "sin f=3";
% Creating a Simulation Data Inspector run
sineRun = Simulink.sdi.Run.create;
sineRun.Name = "Sine Waves";
sineRun.Description = "f=1,2,3";
% Adding the timeseries data to run
add(sineRun,"vars",sin1_ts, sin2_ts, sin3_ts);
% Getting the signal objects and plotting the signal
sin1_sig = getSignalByIndex(sineRun, 1);
sin2_sig = getSignalByIndex(sineRun, 2);
sin3_sig = getSignalByIndex(sineRun, 3);
plotOnSubPlot(sin1_sig,1,1,true);
plotOnSubPlot(sin2_sig,2,1,true);
plotOnSubPlot(sin3_sig,3,1,true);
Simulink.sdi.view;
The documentations for “plotOnSubPlot” and “Simulink.sdi.setSubPlotLayout” functions are as follows:
Hope this helps!

Catégories

En savoir plus sur Analyze Simulation Results dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by