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 CenterFile Exchange에서 Analyze Simulation Results에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by