convert NAN to zero in complex structs.

8 vues (au cours des 30 derniers jours)
Areum Lee
Areum Lee le 25 Oct 2018
Commenté : Guillaume le 25 Oct 2018
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 commentaires
Areum Lee
Areum Lee le 25 Oct 2018
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 le 25 Oct 2018
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.

Connectez-vous pour commenter.

Réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by