How to note the time of specific output in MATLAB?

3 Ansichten (letzte 30 Tage)
Noor Fatima
Noor Fatima am 21 Okt. 2022
Kommentiert: Walter Roberson am 21 Okt. 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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 21 Okt. 2022
Bearbeitet: Walter Roberson am 21 Okt. 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 Kommentare
Noor Fatima
Noor Fatima am 21 Okt. 2022
@Walter Roberson Thank you very much for your response.
Question: is it useful to you to know the iteration number at which the output was seen, or only the elapsed time?
Yes, it will be
Walter Roberson
Walter Roberson am 21 Okt. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by