convert NAN to zero in complex structs.

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 Comments

Is it any NaN value in any field not matter how many deep into your structure you want to set to 0?
Are the fields scalar or do you want to also convert NaNs inside arrays?
Note that NaN and 0 are two completely different concepts and it is usually ill-advised to convert one to the other.
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
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.

Sign in to comment.

Answers (0)

Tags

Asked:

on 25 Oct 2018

Commented:

on 25 Oct 2018

Community Treasure Hunt

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

Start Hunting!