A two dimensional matrix with columns having different length
57 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Fangjun Jiang
on 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};
0 Comments
More Answers (1)
Walter Roberson
on 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).
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!