how do I create this loop?

2 ビュー (過去 30 日間)
Susan Santiago
Susan Santiago 2018 年 10 月 31 日
コメント済み: Star Strider 2018 年 10 月 31 日
I have a timetable that I'm converting to an array. Some of the columns are NaNs so initially, I just changed the columns to zeros before converting it but I don't want to do this since not all values in the column are necessarily NaNs and I don't want to lose that possible data. I was thinking of creating a loop so that if the values are NaNs, it'll be changed to a zero and if the value is something else, it'll be left alone. This is what I tried writing for a column called G
for c = 1:length(TT(:,'G'))
if TT(c,'G')= nan
TT(c,'G') = 0;
else
TT(c,'G') = TT(c,'G');
end
I know i'm calling the if function wrong but i'm not sure how to fix it. if statements always trip me up for some reason

採用された回答

Star Strider
Star Strider 2018 年 10 月 31 日
It might be easier to use the timetable2table (link) function, then the table2array (link) function.
I have no idea if this would work with your data. You will have to experiment.
  6 件のコメント
Susan Santiago
Susan Santiago 2018 年 10 月 31 日
This is perfect, thanks so much!
Star Strider
Star Strider 2018 年 10 月 31 日
As always, my pleasure!

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2018 年 10 月 31 日
編集済み: Andrei Bobrov 2018 年 10 月 31 日
zrs = zeros(size(TT,1),1);
TT.G = zrs;
TT.SG = zrs;
  3 件のコメント
Andrei Bobrov
Andrei Bobrov 2018 年 10 月 31 日
I am fixed my answer.
Susan Santiago
Susan Santiago 2018 年 10 月 31 日
This would just change the whole column to zeros wouldn't it? I explained that that's not what I want to do

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

カテゴリ

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