Effacer les filtres
Effacer les filtres

How to control flag on MATLAB?

7 vues (au cours des 30 derniers jours)
horizon
horizon le 29 Mai 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

Réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by