Removing NaNs from a struct
Ältere Kommentare anzeigen
I have a struct with the following layout:
T X Y
[0,1] [0, 1] [0,5]
[0] [2] [2]
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
[0] [3] [3]
Is there a way to remove all NaN values such that I am left with only:
T X Y
[0,1] [0, 1] [0,5]
[0] [2] [2]
[0] [3] [3]
I am using isnan but keep getting an error "Undefined function 'isnan' for input arguments of type 'struct'".
Thanks
4 Kommentare
Stephen23
am 1 Mai 2019
Manny Kins
am 1 Mai 2019
Manny Kins
am 1 Mai 2019
Walter Roberson
am 1 Mai 2019
Probably the easiest way is to use struct2cell and cellfun(@(C) any(isnan(C(:)), thecell), and then any() that across the proper dimension, to arrive at a logical vector of location to remove. Then delete those from the original struct.
Akzeptierte Antwort
Weitere Antworten (2)
Jos (10584)
am 1 Mai 2019
TF = arrayfun(@(k) isnan(AllData.Passive(k).T(1)), 1:numel(AllData.Passive))
AllData.Passive(TF) = []
1 Kommentar
Manny Kins
am 2 Mai 2019
Bearbeitet: Manny Kins
am 2 Mai 2019
Felipe Ademir aleman hernandez
am 8 Apr. 2020
Bearbeitet: Walter Roberson
am 8 Apr. 2020
Hey, this works for me:
MyNewDataStruct = structfun( @rmmissing , MyDataStruct , 'UniformOutput' , false)
Kategorien
Mehr zu Cell Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!