MATLAB: Remove negative and NaN from cell array.

cell arrays

Hey
I have a cell array A
A= {NaN,-1,-1,0.8,-0.6,[],[]; NaN,NaN,0.9,1,NaN,-0.05,0.4; -1,NaN,NaN,0.7,0.2,NaN,0.79}
I want to remove negative and NaN values from all the rows and store result in a cell array like:
A{1,1}={0.8}
A{2,1}={0.9,1,0.4}
A{3,1}={0.7,0.2,0.79}
Thanks in advance.

Best Answer

NoNan = @(V) V(~isnan(V));
NewA = arrayfun(@(ROWIDX) NoNan([A{ROWIDX,:}]), (1:size(A,1)).', 'Uniform', 0);