How to control flag on MATLAB?

4 views (last 30 days)
horizon
horizon on 29 May 2019
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

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!