Combining Cells into a single cell

How can I combine multiple cells in to a single cell
there are 6 cells, each m x n format (n is 17 in all)
I want a new cell created that just adds up below
so for example Cell1 is 50x17 Cell2 is 30x17 Cell3 is 20x17
new cell should then be : AllCell is 100x17
I thought of:
Allcell=cell(Cell1+Cell2+Cell3,17);
but what then

4 comentarios

Hassan F
Hassan F el 9 de En. de 2013
Editada: Hassan F el 9 de En. de 2013
You should find your way from there on, and combine content of cell arrays.
Jan
Jan el 9 de En. de 2013
It slightly confusing: Do you want AllCell to be a scalar cell, which contains a 100x17 matrix?
Hello kity
Hello kity el 9 de En. de 2013
Editada: Hello kity el 9 de En. de 2013
I found a way but i think it should be easier.
raw is from xlsread, a cell.
A=length(raw1);
B=length(raw2);
C=length(raw3);
D=length(raw4);
E=length(raw5);
F=length(raw6);
lengthcell=A+B+C+D+E+F;
All=cell(lengthcell+5,17);
All(1:A, 1:17)=raw1;
All(A+2:A+B+1, 1:17)=raw2;
All(A+B+3:A+B+2+C, 1:17)=raw3;
All(A+B+C+4:A+B+C+D+3, 1:17)=raw4;
All(A+B+C+D+5:A+B+C+D+E+4, 1:17)=raw5;
All(A+B+C+D+E+6:A+B+C+D+E+F+5, 1:17)=raw6;
between every set of data there is a cell row free.
Jongyoung Song
Jongyoung Song el 24 de En. de 2017
AllCell = [Cell1; Cell2; Cell3];

Iniciar sesión para comentar.

 Respuesta aceptada

Thorsten
Thorsten el 9 de En. de 2013
Editada: Thorsten el 9 de En. de 2013

4 votos

use the standard concatenation operator [ ]
AllCell = [Cell1; Cell2; Cell3; Cell4; Cell5; Cell6];

2 comentarios

Hello kity
Hello kity el 9 de En. de 2013
hmm, i tried this but with , instead of ; inbetween the Cells.
Thank you
kiarash Dousti
kiarash Dousti el 19 de Jul. de 2016
Thanks a lot dear Thorsten. It reclaim me

Iniciar sesión para comentar.

Más respuestas (1)

Jan
Jan el 9 de En. de 2013

15 votos

If your cells are not called "Cell1", "Cell2", ... but you use an index as index (as suggested repeatedly and consequently in this forum), the concatenation is even easier:
C{1} = rand(50, 17);
C{2} = rand(10, 17);
C{3} = rand(40, 17);
C{4} = rand(30, 17);
C{5} = rand(20, 17);
AllC = {cat(1, C{:})};

5 comentarios

Image Analyst
Image Analyst el 9 de En. de 2013
Editada: Image Analyst el 9 de En. de 2013
Why even mess with cells, if it's just a simple numerical matrix at that point? Just simplify it
theBigArray = cat(1, C{:}); % A matrix, not a cell - simpler, yay!
Jan
Jan el 9 de En. de 2013
But the OP asked for the output to be a cell explicitly: "Allcell=cell(...".
Image Analyst
Image Analyst el 9 de En. de 2013
Yeah, I know. But she's a beginner and beginners often think they want something when some other way is better, simpler, and easier. For example to get the 5th row, 16th column you could simply and naturally do theBigArray(5, 16). OR do something more complicated like AllCell(1){5, 16} or maybe it's just AllCell{5, 16} or something like that - I always have to play around with braces and parentheses til I get it right, that's why I avoid cell arrays if at all possible.
giri wira
giri wira el 11 de Jun. de 2015
thanks simon, very usefull
Pooja Patel
Pooja Patel el 24 de Feb. de 2017
thank you so much mr.simon. this is working very well.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de En. de 2013

Comentada:

el 24 de Feb. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by