Do something only, when variable is same for 2 second

3 visualizaciones (últimos 30 días)
martin martin
martin martin el 25 de Abr. de 2019
Comentada: martin martin el 25 de Abr. de 2019
Hello guys,
how can I write a code (cycle) something like "when value is same for 2 second, do something else"? Example below, Im changing variable "a".
a = 1;
"if a = a (for more then 2 second, then ..)"
b = a;
Best regards
  2 comentarios
Adam
Adam el 25 de Abr. de 2019
Editada: Adam el 25 de Abr. de 2019
It sounds like an odd thing to want to do. In your example the
b = a;
line will happen almost instantaneously after
a = 1;
and if you have more complex code it would be dependent on the run time of that code. I can't think of a situation where that would be useful. You can use
doc tic;
doc toc;
for timing things, but I would suggest that the reason for wanting this behaviour in the first place should be questioned ahead of trying to find a way to achieve it. Code based on how long a certain variable happens to have remained unchanged is going to be very brittle and unreliable in general.
martin martin
martin martin el 25 de Abr. de 2019
Thanks man, I solved it with "if" and "pause"
t1 = round(get(handles.slider1,'value'));
pause(0.5)
if t1 == round(get(handles.slider1,'value'))
...
else
return
end

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by