delete NaN rows and columns but

Asked by Andrea on 21 May 2012
Latest activity Commented on by Claudia on 1 Jul 2012

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.

0 Comments

Andrea

Products

No products are associated with this question.

2 Answers

Answer by per isakson on 21 May 2012
Accepted 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

2 Comments

Andrea on 21 May 2012

Thanks, It perfectly works on my code. I really appreciate your instance reply.

Claudia on 1 Jul 2012

Was just looking exactly for that! Thank you! And thanks showing both (column and rows)! It looks easy to change from row to column if you know how ... but if you don't ... can drive you crazy!

per isakson
Answer by wenwu on 27 May 2012

Nice, Thx for your guys question and answer, i learned sth. Thx

0 Comments

wenwu

Contact us