Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Cell Element Delete If....

Subject: Cell Element Delete If....

From: Dave

Date: 2 Jul, 2013 10:06:09

Message: 1 of 2

Hi Everyone,

So I have a <800 x 1> Cell called 'A: created containing doubles of varying dimensions. Now, all I want to do is to be able to delete any empty doubles within the cell. For instance, the first 3 doubles in A have the following dimensions:

<5 x 10> double
<4 x 10> double
<0 x 10> double

So I want to code....if A{i} = [] then delete it. I've tried the following but it didnt work:

 for i=1:length(A)
     if isempty(A_wk{i})
         A_wk(i)=[];
     end
 end

Can I get it to delete them based on the dimensions of the double or what is easiest?

thanks

Subject: Cell Element Delete If....

From: Steven_Lord

Date: 2 Jul, 2013 14:08:30

Message: 2 of 2



"Dave " <davidsheeran@gmail.com> wrote in message
news:kqu8mh$r3c$1@newscl01ah.mathworks.com...
> Hi Everyone,
>
> So I have a <800 x 1> Cell called 'A: created containing doubles of
> varying dimensions. Now, all I want to do is to be able to delete any
> empty doubles within the cell. For instance, the first 3 doubles in A have
> the following dimensions:
>
> <5 x 10> double
> <4 x 10> double
> <0 x 10> double
>
> So I want to code....if A{i} = [] then delete it. I've tried the following
> but it didnt work:
>
> for i=1:length(A)
> if isempty(A_wk{i})
> A_wk(i)=[];
> end
> end
>
> Can I get it to delete them based on the dimensions of the double or what
> is easiest?

Use logical indexing. This call to CELLFUN will iterate through the cells of
A and return a logical array the same size as A with true values
corresponding to empty cells in A and false values corresponding to
nonempties. The second line then extracts those cells in A corresponding to
false values in whichCellsAreEmpty (due to the ~ negation in the indexing.)

whichCellsAreEmpty = cellfun(@isempty, A);
AWithoutEmpties = A(~whichCellsAreEmpty);

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us