Effacer les filtres
Effacer les filtres

A two dimensional matrix with columns having different length

40 vues (au cours des 30 derniers jours)
Aakash
Aakash le 27 Sep 2011
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?

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 27 Sep 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};

Plus de réponses (1)

Walter Roberson
Walter Roberson le 27 Sep 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).

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by