
How do I plot Simulink simulation data in App Designer during simulation?
8 次查看(过去 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!