
How do I plot Simulink simulation data in App Designer during simulation?
7 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2023 年 2 月 20 日
回答済み: MathWorks Support Team
2023 年 3 月 30 日
I am using App Designer to develop an app that controls a Simulink model. I would like to know if it is possible to plot Simulink simulation data in App Designer during simulation, similar to the Scope block.
採用された回答
MathWorks Support Team
2023 年 2 月 20 日
Scope block cannot be included in App Designer at this time. To plot data on UIAxes in a way similar to the streaming scope, you will need to obtain data from Simulink using “add_exec_event_listener” and write code. Here are the steps:
1. Get Simulink block data using “add_exec_event_listener”. You can refer to this answer for more information:
2. To plot the data in UIAxes, you will need functions that trim the data obtained from step 1 and update lines. Below is an example of how the functions work. Please see the attached file for an example App Designer file and Simulink model.
function clipSignalTraces(app) % Get(trim) Signal Data
maxSigLen = 5000;
startX = 0;
for sigIdx = 1:length(app.signalTraces)
hLine = app.signalTraces(sigIdx);
xd = get(hLine,'XData');
sigLen = length(xd);
if sigLen > maxSigLen
startEl = sigLen-maxSigLen+1;
if xd(startEl) > startX
startX = xd(startEl);
end
end
end
if startX == 0, return; end
for sigIdx = 1:length(app.signalTraces)
hLine = app.signalTraces(sigIdx);
xd = get(hLine,'XData');
yd = get(hLine,'YData');
elIdx = find(xd <= startX);
xd(elIdx) = [];
yd(elIdx) = [];
set(hLine,'XData',xd, 'YData', yd);
end
end % clipSignalTraces
function updateSignalTrace(app,sigTag,time,data) % Update signals in UIAxes
for sigIdx = 1:length(app.signalTraces)
hLine = findobj(app.signalTraces(sigIdx),'flat','Tag',char(sigTag(sigIdx)));
assert(~isempty(hLine));
xData = [hLine.XData time];
yData = [hLine.YData data(sigIdx)];
set(hLine, 'XData',xData, 'YData', yData);
end
end % updateSignalTrace

0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Outputs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!