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:
Can mat2cell return a cell array of columns?

Subject: Can mat2cell return a cell array of columns?

From: Jim Rockford

Date: 15 Oct, 2010 19:55:57

Message: 1 of 4


Suppose you have the matrix

 A = [ 1 4;
          2 5
          3 6 ];

I'd like cell2mat to return each column of A as a cell array.

The command

>> X = cell2mat(A', ones(1,size(A,2)))

will return the cell array I want, except each cell array entry has
the shape of a row (and I want columns). Possible?

Thanks,
Jim

Subject: Can mat2cell return a cell array of columns?

From: Sean

Date: 15 Oct, 2010 20:10:06

Message: 2 of 4

Jim Rockford <jim.rockford1@gmail.com> wrote in message <b7309516-06a1-4af4-ae9a-47705def67aa@k10g2000yqa.googlegroups.com>...
>
> Suppose you have the matrix
>
> A = [ 1 4;
> 2 5
> 3 6 ];
>
> I'd like cell2mat to return each column of A as a cell array.
>
> The command
>
> >> X = cell2mat(A', ones(1,size(A,2)))


mat2cell you mean?
X = mat2cell(A,size(A,1),ones(1,size(A,2)))

Subject: Can mat2cell return a cell array of columns?

From: Jim Rockford

Date: 15 Oct, 2010 20:13:38

Message: 3 of 4

On Oct 15, 4:10 pm, "Sean "
<sean.dewol...@nospamplease.umit.maine.edu> wrote:
> Jim Rockford <jim.rockfo...@gmail.com> wrote in message <b7309516-06a1-4af4-ae9a-47705def6...@k10g2000yqa.googlegroups.com>...
>
> > Suppose you have the matrix
>
> >  A = [  1 4;
> >           2 5
> >           3 6 ];
>
> > I'd like cell2mat  to return each column of A  as a cell array.
>
> > The command
>
> > >> X = cell2mat(A', ones(1,size(A,2)))
>
> mat2cell you mean?
> X = mat2cell(A,size(A,1),ones(1,size(A,2)))


Yes, I meant mat2cell, and thank you for the code. Thought I'd tried
that. Thanks again. It works.

Jim

Subject: Can mat2cell return a cell array of columns?

From: Bruno Luong

Date: 15 Oct, 2010 20:21:03

Message: 4 of 4

Simplest command is

num2cell(A,1)

Bruno

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