Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

remove NaN from cell

373 views
Skip to first unread message

mf bruno

unread,
Feb 11, 2009, 4:05:03 AM2/11/09
to
I need your help :
I've got to remove nans from a 12x1 cell without reshaping
if i try one of the solution suggested in this forum

dd_m( all(cellfun(@isnan,dd_m ,'UniformOutput', false),2), : ) = [];

the answer is:
??? Undefined function or method 'all' for input arguments of type 'cell'.

Why?
Please help me
thank you
mfrab

Jos

unread,
Feb 11, 2009, 6:10:03 AM2/11/09
to
"mf bruno" <mfb...@email.it> wrote in message <gmu4bv$c9r$1...@fred.mathworks.com>...

You got me confused. How do you expect to remove things without reshaping?

Perhaps you can give a small example of the expected input and output?

A = {1 ; 2:10 ; repmat(3,3,3) ; NaN ; 5 ; 'text'} ; % a 6x1 cell with 1 NaN

% -> B = {...} ??

Jos

mf bruno

unread,
Feb 11, 2009, 6:58:01 AM2/11/09
to
you're right!!
let me explain:
i've got a 12x1 cell

first matrix of the cell
1 2 3 4 5 6 7
NaN NaN Nan NaN NaN Nan
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7

second matrix of the cell
NaN NaN Nan NaN NaN Nan
1 2 3 4 5 6 7
1 2 3 4 5 6 7
NaN NaN Nan NaN NaN Nan
1 2 3 4 5 6 7

and so on

I vant to remove rows that contains NaNs
i expect this result:
first matrix of the cell
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7

second matrix of the cell
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7

I wrote without reshaping because i tried to remove Nans and the result was an array not a matrix.

thank you for your attention
mfrab

Jos

unread,
Feb 11, 2009, 8:02:04 AM2/11/09
to
"mf bruno" <mfb...@email.it> wrote in message <gmueg9$bpc$1...@fred.mathworks.com>...

> you're right!!
> let me explain:

First, reconsider your problem and the final solution. Is this problem just part of a larger problem, and do you really need to throw out rows in every cell to arrive at the final solution or can you take another route? The links between cells may become disrupted and it may, for instance, be wiser to store the contents of the 12 cells in different variables.

That being said, and assuming number of columns in each cell is the same, try this:

C = {[10 20 ; NaN NaN ; 11 12] ; [30 40 ; 31 41 ; NaN 42] ; [NaN NaN ; NaN NaN ; 52 62]}

D = cat(1,C{:})
q = ~all(isnan(D),2)
RES = mat2cell(D(q,:),sum(reshape(q,size(C{1},1),[])))

hth
Jos

mf bruno

unread,
Feb 11, 2009, 8:15:20 AM2/11/09
to
It works!! great!!
Thank you so much
I need to store data in cell because it's easier (for me) to
plot them with a for loop
cheers
mf

"Jos " <#10...@fileexchange.com> wrote in message <gmui8c$d59$1...@fred.mathworks.com>...

Jos

unread,
Feb 11, 2009, 8:23:02 AM2/11/09
to
"mf bruno" <mfb...@email.it> wrote in message <gmuj18$leh$1...@fred.mathworks.com>...

> It works!! great!!
> Thank you so much

You're welcome. In return, try to actually understand the code and not simply copy and paste it ;-)

Best,
Jos

0 new messages