フィルターのクリア

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

2 ビュー (過去 30 日間)
Pree
Pree 2015 年 9 月 3 日
コメント済み: Star Strider 2015 年 9 月 3 日
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!)
  2 件のコメント
Pree
Pree 2015 年 9 月 3 日
Thank you.
Star Strider
Star Strider 2015 年 9 月 3 日
My pleasure.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by