Find NaN in a cell array and only delete the NaNs

35 views (last 30 days)
How can I delete NaN s from a cell array (only the NaN elements not the whole column or row)?

Accepted Answer

Matt J
Matt J on 11 Apr 2019
results(j)= sqrt( mean(array{j}.^2,'omitnan') );

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
Edited: 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))={''};

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!