A two dimensional matrix with columns having different length

57 visualizaciones (últimos 30 días)
How can I create a two dimensional matrix having different column length? For example, can I assign two column vectors C1 = {1 2 3 4}' and C2 = {1 2 3 4 5}' to a single matrix C?

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 27 de Sept. de 2011
No. You can't. However, you can use cell array.
C1=[1 2 3 4]';
C2=[1 2 3 4 5]';
C={C1,C2};

Más respuestas (1)

Walter Roberson
Walter Roberson el 27 de Sept. de 2011
You cannot do that with a numerical array, but you can use cell arrays.
C = {C1, C2};
This will, however, be "two dimensional" only in the degenerate sense that one of the dimensions could be the constant 1. C{2} would be the same as C{1,2} which would be the entire column vector C2. You could use C{2}(3) where you probably would have instead preferred to index as C(3,2) (third row, 2nd column).

Categorías

Más información sobre Creating and Concatenating Matrices 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