MATLAB: Removing cells containing Inf or NaNs cell arrays Hi folks. I have a cell array, each cell containing a column vector. Is there any way to check if a cell contains inf or nans and if so deleting them? I.e if cell{3}=[inf;inf;1;2] then i want to remove it. Thanks. Best Answer YourCellArray( cellfun( @(C) any(isnan(C) | isinf(C)), YourCellArray ) ) = []; Related SolutionsMATLAB: Delete empty [] {1×7 cell} {1×2 cell} z(cellfun('isempty',z))=[] MATLAB: Are Infs still faster than NaNs Hmmm, possibly a false alarm. In the tests below, minimization operations involving NaNs are still noticeably slower, n=1e4;k=1e4; A=rand(n,k);b=randi(k,n,1); idx=bsxfun(@lt,b,(1:k)); A(idx)=nan; tic c=min(A,[],2); toc %Elapsed time is 0.348245 seconds. A(idx)=inf; tic c=min(A,[],2); toc %Elapsed time is 0.126220 seconds.Still, I seem to remember that a lot of other operations were slower, too. Related QuestionCan I convert empty strings to NaNs automatically in a cell arrayDetermination between Inf and -InfNaN vs. InfCombine a cell array of cell arrays to a single cell array
Best Answer