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:
How to put array into a cell

Subject: How to put array into a cell

From: Widt

Date: 26 Jan, 2012 10:20:09

Message: 1 of 5

Hi.

I have three column vectors (a, b and c) which are n items in length.
I need to get each item of these vectors into [3x3] matrices which I have nested inside a cell M. M has n numbers of [3x3] matrices.

This is what I'm trying to do:

M = cell([10,1]);
M(:,1) = {[a b c]};

This is not working since I end up with n times [10,3] matrices. I want to get n times [1x3] matrices. Can anyone please advice how to do this without using a loop?

Thanks in advance.

Subject: How to put array into a cell

From: dpb

Date: 27 Jan, 2012 15:11:59

Message: 2 of 5

On 1/26/2012 4:20 AM, Widt wrote:
> Hi.
>
> I have three column vectors (a, b and c) which are n items in length.
> I need to get each item of these vectors into [3x3] matrices which I
> have nested inside a cell M. M has n numbers of [3x3] matrices.
...

I can't parse the request, sorry.

How about a (small) example input/desired output?

--

Subject: How to put array into a cell

From: Widt

Date: 30 Jan, 2012 12:20:10

Message: 3 of 5

dpb <none@non.net> wrote in message <jfuert$s1f$1@speranza.aioe.org>...
> On 1/26/2012 4:20 AM, Widt wrote:
> > Hi.
> >
> > I have three column vectors (a, b and c) which are n items in length.
> > I need to get each item of these vectors into [3x3] matrices which I
> > have nested inside a cell M. M has n numbers of [3x3] matrices.
> ...
>
> I can't parse the request, sorry.
>
> How about a (small) example input/desired output?
>
> --
Here is an example. If I define;
 a = [1 2 3 4 5]';
b = [6 7 8 9 10]';
c = [11 12 13 14 15]';
M = cell(5,1);

and then I write;
M(:,1) = {[a;b;c]}

I want the first value of each column vector to be put into the column of the first matrix in the M cell etc. like this:
{[1 6 11];[2 7 12] etc.}

What I get is the column vectors a,b and c put into a column vector 5 times.
M = [15x1 double]
      [15x1 double]
      [15x1 double]
      [15x1 double]
      [15x1 double]

Thanks in advance for any help on this.

Subject: How to put array into a cell

From: Bruno Luong

Date: 30 Jan, 2012 13:09:10

Message: 4 of 5

Your explaination is still unclear to me, but try this:

a = [1 2 3 4 5]';
b = [6 7 8 9 10]';
c = [11 12 13 14 15]';

M = num2cell([a b c],2)
M{1,:}
M{2,:}

% Bruno

Subject: How to put array into a cell

From: Widt

Date: 30 Jan, 2012 14:00:10

Message: 5 of 5

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jg64pm$jji$1@newscl01ah.mathworks.com>...
> Your explaination is still unclear to me, but try this:
>
> a = [1 2 3 4 5]';
> b = [6 7 8 9 10]';
> c = [11 12 13 14 15]';
>
> M = num2cell([a b c],2)
> M{1,:}
> M{2,:}
>
> % Bruno

This is what I was trying to get.

Thank you.

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