How to control flag on MATLAB?
4 次查看(过去 30 天)
显示 更早的评论
The following code is what I'm expecting but only the transmit part which displays "Transmit" three times every 2 seconds.
While the period until the exit of the for loop, I would like to continue the plotData function and once exit the for loop, I hope to stop the execution of the plot function as well.
How can I change the following code?
How can I continue to plot while the flag, "stat", is true, and stop to plot when the flag is false?
%data
global accumulateData
%status
global stat
stat = true;
if(stat == true)
%h = addlistener(s, 'DataAvailable', @plotData);
h = @plotData;
end
%Transmit 3 times every 2 seconds
for i = (1:3)-1
if i == 3
fprintf("end\n");
pause(2)
stat = false;
exit();
end
fprintf("Transmit\n");
pause(2);
end
function plotData(src, event)
%plot(event.TimeStamps, event.Data);
fprintf("plot\n");
end
%output
>> untitled
Transmit
Transmit
Transmit
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!