How to note the time of specific output in MATLAB?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Noor Fatima
el 21 de Oct. de 2022
Comentada: Walter Roberson
el 21 de Oct. de 2022
tic
Time = 0;
for ii = 1:n
if Time >= 20
break
end
Output = ....
Time = toc;
end
The output ranges from 1 to 10.
I want to execute code for 20 sec.
But witin 20 sec I want to note the time of some specific outputs when occur first time.
e.g., there is a chance that 2 occurs multiple times, but I want to note the time when 2 first time occur as an output within 20 seconds like wise 6, 8, and 10.
Furthermore, the output comes in an increasing order that is if 2 comes, then after that the number 2 0r greater than 2 comes, can not be less than 2.
0 comentarios
Respuesta aceptada
Walter Roberson
el 21 de Oct. de 2022
Editada: Walter Roberson
el 21 de Oct. de 2022
neverseen = true(1,10);
seenwhen = nan(1,10);
tic
Time = 0;
for ii = 1:n
if Time >= 20
break
end
Output = ....
Time = toc;
if neverseen(Output)
seenwhen(Output) = Time;
neverseen(Output) = false;
end
end
Now if neverseen(6) is true (for example) then that means that you did not receive any 6's and that seenwhen(6) [or whatever] is not valid. But if neverseen(6) is false then that means that you did seen a 6 on output and that seenwhen(6) tells you the time at which you saw it.
Question: is it useful to you to know the iteration number at which the output was seen, or only the elapsed time?
2 comentarios
Walter Roberson
el 21 de Oct. de 2022
neverseen = true(1,10);
seenwhen = nan(1,10);
seeniter = nan(1,10);
tic
Time = 0;
for ii = 1:n
if Time >= 20
break
end
Output = ....
Time = toc;
if neverseen(Output)
seenwhen(Output) = Time;
seeniter(Output) = ii;
neverseen(Output) = false;
end
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!