필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by