MATLAB Answers

Find NaN in a cell array and only delete the NaNs

49 views (last 30 days)
MatlabUser17
MatlabUser17 on 11 Apr 2019
Answered: Pruthvi G on 12 Mar 2020
How can I delete NaN s from a cell array (only the NaN elements not the whole column or row)?

  0 Comments

Sign in to comment.

Accepted Answer

More Answers (2)

madhan ravi
madhan ravi on 11 Apr 2019
C(cellfun(@(x)any(isnan(x)),C))=[]

  2 Comments

MatlabUser17
MatlabUser17 on 11 Apr 2019
This deletes everything within a cell. Let me be more clear, let's assume:
matrix=[1,1,3,5;2,NaN,2,2;4,4,4,NaN]
[Mx My]=size(matrix)
for j=1:My;
array{j}=matrix(:,j);
% % array(cellfun(@(x)any(isnan(x)),array))=[]
results(j)=rms(array{j})
end
I want to calculate the RMS within each individual cell without considering NaN in each cell.

Sign in to comment.


Pruthvi G
Pruthvi G on 12 Mar 2020
Data(cellfun(@(cell) any(isnan(cell(:))),Data))={''};

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!