How to control flag on MATLAB?

4 ビュー (過去 30 日間)
horizon
horizon 2019 年 5 月 29 日
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 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by