フィルターのクリア

How to note the time of specific output in MATLAB?

1 回表示 (過去 30 日間)
Noor Fatima
Noor Fatima 2022 年 10 月 21 日
コメント済み: Walter Roberson 2022 年 10 月 21 日
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.

採用された回答

Walter Roberson
Walter Roberson 2022 年 10 月 21 日
編集済み: Walter Roberson 2022 年 10 月 21 日
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 件のコメント
Noor Fatima
Noor Fatima 2022 年 10 月 21 日
@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 2022 年 10 月 21 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by