How to remove rows in a cell array with a number of Nans major than a threshold
5 views (last 30 days)
Show older comments
Hi guys, I have a cell array (see attached), and I want eliminate the row of the cell array, that contain a number of nan major than a threshold, ex 50, so if the cell in the cell array contain a number of NaN major of 50, i want to eliminate that row from the array. I tried different solutions, with cellfun but i did'nt understand how to set the treshold. Because for a matrix i did with function rmmissing, so I tried also this, but it does not work.
0 Comments
Accepted Answer
Dyuman Joshi
on 12 Jun 2022
Edited: Dyuman Joshi
on 12 Jun 2022
%random data
y={NaN(1,50);[zeros(1,5) NaN(1,35) ones(1,25)];[primes(100) NaN(1,37)];...
[0.5*(1+sqrt(5)) pi exp(1) NaN(1,55)]}
idx=[];
for i=1:size(y,1)
if sum(isnan(y{i,1}))>=50 %checking the threshold condition
idx=[idx i]; %storing index of rows that cross the threshold
end
end
y(idx,:)=[] %deleting corresponding rows
2 Comments
More Answers (0)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!