MATLAB Answers

How to remove NaNs from a structure

38 ビュー (過去 30 日間)
Casey McMahon
Casey McMahon 2019 年 7 月 8 日
編集済み: madhan ravi 2019 年 7 月 8 日
Hi,
I have a structure that has eighteen variables (columns) and 594 participants (rows) (18 x 594), the first two variables are strings, the next sixteen are doubles.
My goal is to identify the NaNs and then remove the whole row.
This is what I have from when I did work with a matrix:
countNans = sum(isnan((DATA),2); %Counts missing values (nans) per row over the 2nd dimension
idClean = find(countNans==0); %Only keep rows of participants with all data
cleanData = cleanData(idClean,:);
However, this method is no longer working, with MATLAB saying that isnan does not work for structures.
Thanks!

  1 件のコメント

madhan ravi
madhan ravi 2019 年 7 月 8 日
Attach your data file.

サインインしてコメントする。

回答 (1 件)

Abhishek Kumar
Abhishek Kumar 2019 年 7 月 8 日
編集済み: madhan ravi 2019 年 7 月 8 日
A workaround for this would be converting the struct to matrix and then get rid of the NaNs and if you need it again convert it to struct.
cell2mat(struct2cell(YourStructure)) % this will convert your structure to matrix
cell2struct(cellArray, fields, dim) % this will convert it again to struct

  0 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by