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!