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

2 ビュー (過去 30 日間)
Pavan
Pavan 2023 年 8 月 26 日
回答済み: Ashok 2024 年 9 月 17 日
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 件のコメント
Mike
Mike 2023 年 11 月 3 日
Did you find a work around for this?
Pavan
Pavan 2023 年 11 月 3 日
編集済み: Pavan 2023 年 11 月 3 日
Nope. Maybe more votes on this would let Mathworks know that this is something on their users' want list.

サインインしてコメントする。

回答 (1 件)

Ashok
Ashok 2024 年 9 月 17 日
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!

カテゴリ

Help Center および File ExchangeAnalyze Simulation Results についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by