MATLAB: Delete NaN rows and columns but

delete nan rows and columns butimage analysisimage processing

I want to remove the NaN column and row in my image so the size will be decreased, but since I used the "find' command it Matlab, it also remove the NaN that changes the shape of the image,too. I just want to remove the NaN data as much as possible but keep the other NaNs that cannot be removed in order to have the same shape.

Best Answer

Is this close?
M( all( isnan( M ), 2 ), : ) = []; % removes all rows with all nans
M( :, all( isnan( M ), 1 ) ) = []; % and columns
and you might want to try the FEX contribution inpaint_nans