Removing NaNs from a struct
古いコメントを表示
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 件のコメント
Stephen23
2019 年 5 月 1 日
Manny Kins
2019 年 5 月 1 日
Manny Kins
2019 年 5 月 1 日
Walter Roberson
2019 年 5 月 1 日
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.
採用された回答
その他の回答 (2 件)
Jos (10584)
2019 年 5 月 1 日
TF = arrayfun(@(k) isnan(AllData.Passive(k).T(1)), 1:numel(AllData.Passive))
AllData.Passive(TF) = []
1 件のコメント
Manny Kins
2019 年 5 月 2 日
編集済み: Manny Kins
2019 年 5 月 2 日
Felipe Ademir aleman hernandez
2020 年 4 月 8 日
編集済み: Walter Roberson
2020 年 4 月 8 日
Hey, this works for me:
MyNewDataStruct = structfun( @rmmissing , MyDataStruct , 'UniformOutput' , false)
カテゴリ
ヘルプ センター および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!