trying to create a loop that finds a value in an array and creates a matrix with it

1 回表示 (過去 30 日間)
I have an array TT where the first column is matlab serial date numbers and each other column is data for various variables.
I want to create a loop where the interation is
i = datenum(2018,1,1,00,00,00):0.208:datenum(2018,12,4,00,00,00)
0.208 is the difference between half hour periods in matlab serial date numbers. so i should loop through all the values in my first column. The problem is that these values are floating points. additionally, i'm not sure how to create a matrix with this. For more detail, what I want to do is create a matrix where for each i value, the matrix either has the corresponding variable data or if there is no value in TT that matches i, it'll insert an NaN into the matrix. I hope this makes sense. Any guidance would be appreciated.
  3 件のコメント
Stephen23
Stephen23 2018 年 11 月 17 日
編集済み: Stephen23 2018 年 11 月 17 日
"0.208 is the difference between half hour periods in matlab serial date numbers"
Almost. Serial date numbers count up in days, so one half hour has a value of
>> 1/24/2
ans = 0.020833
Susan Santiago
Susan Santiago 2018 年 11 月 19 日
You said in a .mat file so I assume you mean my array. This is it. If this is not what you meant, please let me know. And yes thank, I miswrote. It should be 0.020833

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

採用された回答

Walter Roberson
Walter Roberson 2018 年 11 月 17 日
If you have a new enough version then I recommend changing to timetable objects and using retime()
Otherwise consider using interp1() . If that is not suitable, then use ismembertol() to find matching items. If your system is too old to have ismembertol() then loop with testing ranges of values.
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2018 年 11 月 17 日
編集済み: Andrei Bobrov 2018 年 11 月 17 日
+1
Susan Santiago
Susan Santiago 2018 年 11 月 19 日
I have the 2017 version. I'll look into ismembertol. Thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by