MATLAB: Fill an array with different size vectors

different size vectorsextend arrayfill arrayresize array

I have different sized vectors and an array to fill
A=[1,2,3,4];
B=[5,6];
C=[7,8,9];
ARRAY=zeros(5);
And I want to reach this:
OBJECTIVE =
1 2 3 4 0
5 6 0 0 0
7 8 9 0 0
0 0 0 0 0
0 0 0 0 0
Any idea? Also if there is any way to extend vectors to certain length I highly appreciate to know.

Best Answer

For an arbitrary number of vectors use a cell array, then looping is trivial:
>> D = {[1,2,3,4],[5,6],[7,8,9]};
>> M = zeros(5,5);
>> for k = 1:numel(D), M(k,1:numel(D{k})) = D{k}; end
>> M
M =
1 2 3 4 0
5 6 0 0 0
7 8 9 0 0
0 0 0 0 0
0 0 0 0 0