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:
Concatenating cells

Subject: Concatenating cells

From: Diego Zegarra

Date: 19 Oct, 2008 19:29:02

Message: 1 of 2

I am having a problem concatenating cells that have different dimension. Lets see here is how it is. I have a cell called MSchT that has a bx1 number of cells. Now inside every cell of MSchT, (e.g. MSchT{1,1}), there is one value to begin with, but as you go through the loop it saves values into one of these cells at a time and then I have to concatenate the values again. So lets see a short example, after it saves the first value it looks like this:

MSchT{1,1} = [124 156]
MSchT{2,1} = [114]
MSchT{3,1} = [119]

Since they do not have the same number of columns it is not letting me concatenate them.

I have been using the following code,

minmach = cell2mat(MSchT);

I would like to be able to concatenate, and if for whatever reason I have to give a value to the empty spots just give 0's so it looks like this:

minmach = [124,156;
           114, 0;
           119, 0]

Thanks in advance for your help and time!

Subject: Concatenating cells

From: madzientist z

Date: 19 Oct, 2008 22:19:02

Message: 2 of 2

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gdg1pu$73v$1@fred.mathworks.com>...
> I am having a problem concatenating cells that have different dimension. Lets see here is how it is. I have a cell called MSchT that has a bx1 number of cells. Now inside every cell of MSchT, (e.g. MSchT{1,1}), there is one value to begin with, but as you go through the loop it saves values into one of these cells at a time and then I have to concatenate the values again. So lets see a short example, after it saves the first value it looks like this:
>
> MSchT{1,1} = [124 156]
> MSchT{2,1} = [114]
> MSchT{3,1} = [119]
>
> Since they do not have the same number of columns it is not letting me concatenate them.

why dont you reformulate your code so that either

a) you fill the matrix directly instead of filling the cell array within the loop

or

b) fill the cell array with zeros so that each cell has the same number of columns

or

c) dont use cell2mat, instead write a little function with a for loop that creates a matrix from the cell, with zeros where necessary..

hth

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