How to combine rows of cell array into corresponding single cell

24 visualizaciones (últimos 30 días)
Maii el 26 de Mzo. de 2020
Comentada: Maii el 26 de Mzo. de 2020
Hi!
I want to combine rows of a cell array into a single cell. Such that a cell array of dimension 5*4 comes as a cell array of 5*1 where each cell is a cell array of 1*4. I want to remove the for loop, since my cell matrices are huge.
For example:
a={123;'xyz';'abc';'asd';123};
b={'xyz';123;243;'zxy';123};
I can use the following for loop to get the result. But is it possible without a for loop?
for i=1:1:size(a,1)
c{i,1}={a(i) b(i)};
end
result c={{123, 'xyz'};{'xyz', 123};{'abc', 243};{'asd', 'zxy'};{123, 123}};
Thank you!
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Bhaskar R el 26 de Mzo. de 2020
c = cellfun(@(x, y){x,y}, a,b,'UniformOutput',false)
1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Maii el 26 de Mzo. de 2020
Thank you!! it works well!

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by