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:
3D Matrices

Subject: 3D Matrices

From: Simon Buckley

Date: 11 Aug, 2010 14:40:23

Message: 1 of 4

Hi,

I have a Cell array of <15x405 cell> . In each cell there are 100 values. I want to change it to a Matrix of (15 x 405 x 100). Does anyone know how I can do this quickly?

Thanks

Subject: 3D Matrices

From: Matt J

Date: 11 Aug, 2010 14:51:04

Message: 2 of 4

"Simon Buckley" <Simonthomasbuckley@gmail.com> wrote in message <i3ucom$pmn$1@fred.mathworks.com>...
> Hi,
>
> I have a Cell array of <15x405 cell> . In each cell there are 100 values. I want to change it to a Matrix of (15 x 405 x 100). Does anyone know how I can do this quickly?
==========

One way...

C=cellfun(@(x) reshape(x,1,1,100), YourCell,'uni',0);
Matrix=cell2mat(C);

Subject: 3D Matrices

From: Sean

Date: 11 Aug, 2010 15:00:23

Message: 3 of 4

"Simon Buckley" <Simonthomasbuckley@gmail.com> wrote in message <i3ucom$pmn$1@fred.mathworks.com>...
> Hi,
>
> I have a Cell array of <15x405 cell> . In each cell there are 100 values. I want to change it to a Matrix of (15 x 405 x 100). Does anyone know how I can do this quickly?
>
> Thanks

An example:
%Test Data
A = cell(2,2);
A = cellfun(@(x)[1 2 3],A,'uni',false);
%Each cell has vector [1 2 3] in it

%Engine
cell2mat(cellfun(@(x)reshape(x,1,1,numel(x)),A,'uni',false))

%Algorithm:
%reshape each cell so the vector is along the third dimension
%make it a matrix.

Subject: 3D Matrices

From: Simon Buckley

Date: 11 Aug, 2010 15:00:23

Message: 4 of 4

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i3udco$7us$1@fred.mathworks.com>...
> "Simon Buckley" <Simonthomasbuckley@gmail.com> wrote in message <i3ucom$pmn$1@fred.mathworks.com>...
> > Hi,
> >
> > I have a Cell array of <15x405 cell> . In each cell there are 100 values. I want to change it to a Matrix of (15 x 405 x 100). Does anyone know how I can do this quickly?
> ==========
>
> One way...
>
> C=cellfun(@(x) reshape(x,1,1,100), YourCell,'uni',0);
> Matrix=cell2mat(C);

Thanks Matt

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