convert NAN to zero in complex structs.

조회 수: 8 (최근 30일)
Areum Lee
Areum Lee 2018년 10월 25일
댓글: Guillaume 2018년 10월 25일
Hi folks,
I am asking about converting NAN to zero in the complex struct data. Since I am using an input JSON file and open in the Matlab, it is a little bit difficult to change the whole structure as I wish.
Currently my data is 1*1 struct with 611 fields, and each field has 2 different fields and one of them is another 3*1 struct.
so it is like, under data I have data.x1 contains 2 field and under seconds field I have data.x1.data
If I have NAN under data.x1.data how can I get this value up to data.x611.data and convert it to '0'.
I tried to use 'if loop' but it seems like super complicated and long...
I am looking for the other way or simple way.
and advice for me?
Best Regards, Ali
  댓글 수: 3
Areum Lee
Areum Lee 2018년 10월 25일
yes No matter how deep it is I want to set NAN as 0 I am trying to convert all the fields into arrays. I am aware that NAN and 0 is different but I don't need this NAN,But prefer to have 0
Guillaume
Guillaume 2018년 10월 25일
The NaN in matlab will come from null in the json. It probably would be simpler to replace these null in the json by 0 rather than navigating a possibly complex structure. The only danger may be that null may appear in th json as a field name or in a string (where it shouldn't be touched). Is this a possibility in your case?
If it's not then it's trivial to convert the null to 0. Otherwise, I'll have to think a bit more about which approach is the easiest.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 JSON Format에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by