how do I create this loop?
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2018년 10월 31일
편집: Andrei Bobrov
2018년 10월 31일
zrs = zeros(size(TT,1),1);
TT.G = zrs;
TT.SG = zrs;
댓글 수: 3
Susan Santiago
2018년 10월 31일
Andrei Bobrov
2018년 10월 31일
I am fixed my answer.
Susan Santiago
2018년 10월 31일
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!