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 indexing

Subject: Cell indexing

From: Nate

Date: 8 Jun, 2011 18:12:04

Message: 1 of 5

I'm trying to do this:

A{1,1} = {'a' 'a'};
A{2,1} = {'b' 'b'};

for n = 1:2
B{n} = A{n,1}(1)
end

but without the loop.

Something like,

B = A{:}(1)

But that doesn't work.

All help is appreciated.

Thanks,

Nate

Subject: Cell indexing

From: ImageAnalyst

Date: 8 Jun, 2011 18:52:01

Message: 2 of 5

Nate:
Are you trying to do this:

A(1,:) = {'a' 'a'};
A(2,:) = {'b' 'b'}
% OR can do in one line like this: A = {'a' 'a'; 'b' 'b'}

B = A(:,1)

where B is the first column of A?

Subject: Cell indexing

From: Nate

Date: 8 Jun, 2011 19:15:21

Message: 3 of 5

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <806ffba6-9763-4310-b6ac-5acbe7a51efd@f2g2000yqh.googlegroups.com>...
> Nate:
> Are you trying to do this:
>
> A(1,:) = {'a' 'a'};
> A(2,:) = {'b' 'b'}
> % OR can do in one line like this: A = {'a' 'a'; 'b' 'b'}
>
> B = A(:,1)
>
> where B is the first column of A?

Here is my how I am getting cell A.

C = {'a'; 'b c'};

A = cellfun( @textscan, C, cellstr( repmat( ('%s'), length(C), 1) ) );

Then A looks like,

A = {1x1 cell}
       {2x1 cell}

where,

A{1,1} = 'a'
A{2,1} = {'b'; 'c'}

Subject: Cell indexing

From: ImageAnalyst

Date: 8 Jun, 2011 19:58:56

Message: 4 of 5

Tell me in words, what you want B to be. Because it's getting
complicated. The first cell of A contains a character array but the
second cell contains another cell array. Maybe the third element
would be a cell containing a cell array containing yet more cell
arrays. Makes my head spin. Why can't the second cell of A also be a
character array - a 2 by 1 array rather than a cell? And then I'm not
sure if B would capture the 'b' and the 'c' or just the 'b'.

Subject: Cell indexing

From: Nate

Date: 8 Jun, 2011 20:31:04

Message: 5 of 5

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <5f6c345b-7692-4807-b4b5-9f85f7aa3992@ct4g2000vbb.googlegroups.com>...
> Tell me in words, what you want B to be. Because it's getting
> complicated. The first cell of A contains a character array but the
> second cell contains another cell array. Maybe the third element
> would be a cell containing a cell array containing yet more cell
> arrays. Makes my head spin. Why can't the second cell of A also be a
> character array - a 2 by 1 array rather than a cell? And then I'm not
> sure if B would capture the 'b' and the 'c' or just the 'b'.

I'm sorry for the confusion.

What I'm trying to do, is to set B equal to the first white space delimited word of C.

This is a little more insight into my approach,

Basically, cell array C is a cell array of strings,
C = {'a'; 'b c'; 'd'}
Where,
C{1,1} = 'a'
C{2,1} = 'b c'
C{3,1} = 'd'
Cell array C will only grow in dimension 1, there will never be a C{2,1}.

Then cell array A is created by making use of the function textscan to split up cell array C using the default white space delimiter. This means that each cell of cell array A will be a cell containing each of the strings of their respective cell in cell array C.

Then cell array B is the first cell of each cell of cell array A.

Does that make any sense?

Tags for 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