Borrar filtros
Borrar filtros

how can i combine contents of two cell arrays into one cell array of same length

1 visualización (últimos 30 días)
I have two cell arrays
Bill = {[1 2 3 4 5];[2 4 6 8 10]};
Ted = {[6 7 8 9 10];[12 14 16 18 20]};
and I want to merge them together so that
Excell = {[1 2 3 4 5 6 7 8 9 10]; [2 4 6 8 10 12 14 16 18 20]};
the only thing I can think of to combine them is
Excell = cellfun(@(v,w) [v,w],Bill,Ted,'UniformOutput',0)
but I imagine that there is a better more compact way to do this
thanks

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 14 de Nov. de 2014
Joshua - I think that your solution works well. An alternative is the following
Excell = mat2cell(cell2mat([Bill , Ted]),[1 1]);
where we just combine the two cell arrays as [Bill , Ted] and then convert it to a 2x10 matrix with cell2mat. We then convert back to a cell array as mat2cell(...,[1 1]) where we use the [1 1] to indicate the row dimensions of the new cell array.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by