Borrar filtros
Borrar filtros

How to control flag on MATLAB?

7 visualizaciones (últimos 30 días)
horizon
horizon el 29 de Mayo de 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

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by