Borrar filtros
Borrar filtros

How to concatenate lines in cell arrays

7 visualizaciones (últimos 30 días)
Hugo
Hugo el 15 de Mzo. de 2022
Editada: Stephen23 el 8 de Abr. de 2022
Hi,
I have a Cell array, name DATA with 5*50 cells. Each cell has a 1000*30 matrix
I would like to obtain a new matrix that contains the concatenation of the column 1 and all lines (:,1), for all the 50 columns. I need all the lines of all cells in all columns to show up as a resulting matrix, named MR, of dimensions 40000*50.
Right now I have the following code:
for j=1:1:50
MR(:,j)=cat(1,DATA{1,j}(:,1),DATA{2,j}(:,1),DATA{3,j}(:,1),DATA{4,j}(:,1),DATA{5,j}
end
However, the code write all the columns with the same values, so definitely there is something wrong with it. Any help is appreciated.
Best regards,
  3 comentarios
Hugo
Hugo el 15 de Mzo. de 2022
Dear Jan,
I am sorry. I apologize for my mistake. Each cell of the array DATA has dimensions 1000*1
Jan
Jan el 16 de Mzo. de 2022
So you have a {5 x 50} cell array containing [1000 x 1] vectors. Then I still do not understand, how you can obtain a [40000 x 50] matrix.

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 15 de Mzo. de 2022
% 5-by-50 cell array, each cell containing a 1000-by-1 column vector:
DATA = repmat({(1:1000).'},5,50);
% combine all cells into a 5000-by-50 matrix:
DATA_MAT = cell2mat(DATA);
  3 comentarios
Stephen23
Stephen23 el 15 de Mzo. de 2022
Editada: Stephen23 el 8 de Abr. de 2022
Of course, you use your DATA array.
_ just made up some data so that they could run their code on something. Code does not run on air.
Use your DATA. Not the fake DATA that _ kindly used to demonstrate their code with.
Voss
Voss el 15 de Mzo. de 2022
@Hugo: As @Stephen points out, I made up values for DATA just for demonstration purposes. In fact you may only need to run the second line of my answer (with your DATA variable), in order to do what you want:
DATA_MAT = cell2mat(DATA);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by