
How do I plot Simulink simulation data in App Designer during simulation?
조회 수: 10 (최근 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!