필터 지우기
필터 지우기

How to add a number to an element of a vector which meets a certain criteria?

조회 수: 2 (최근 30일)
I have a vector which has sleep times. Its length is 915. But just for an example lets say,
t=[21.33; 22.45; 23.11; 23.67; 0.13; 1.56; 2.33];
The last 3 elements are times after midnight. So I want to add 24 to times after midnight. How can I do it? I tried using if statement.
if t<5
t=t+24
end
but this doesn't work.

채택된 답변

Star Strider
Star Strider 2015년 9월 3일
This works:
t=[21.33; 22.45; 23.11; 23.67; 0.13; 1.56; 2.33];
t(t<5) = t(t<5)+24
t =
21.33
22.45
23.11
23.67
24.13
25.56
26.33
This approach uses ‘logical indexing’ to specifically address only the elements you want. (Using decimal notation for the time makes this much easier!)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by