0
votes

I have a 2 column vector with different lengths y1 and y2. I want to mixed them together in one matrix.

This matrix should have y1 and y2 as a rows, but they have different lengths. Is it possible to add 0 to shorter vector that it has the same length as longer one?

2

2 Answers

1
votes

Many ways to do this, here is one:

>> y1 = [1;2;3;4;5];
>> y2 = [7;8;9];
>> z = zeros(2, max(length(y1), length(y2)));
>> z(1, 1:length(y1)) = y1;
>> z(2, 1:length(y2)) = y2

z =

     1     2     3     4     5
     7     8     9     0     0
0
votes

vec2mat does that easily:

vec2mat([y1; y2], max(numel(y1), numel(y2)))