MATLAB: Appending data with different sizes

vertcat

Hi,
I have a loop which produces data of differnt sizes and want to have the results in a single array. The sizes of the data cannot be pre-determined. For example 1st itteration produces the following
a = [1 2 3;4 5 6]
the second iteration produces
a = [1 2 3 4;4 5 6 7;6 7 8 9]
I want the final result to be
b = [1 2 3 0 ;4 5 6 0;1 2 3 4;4 5 6 7;6 7 8 9]
Thanks

Best Answer

aa = [1 2 3;4 5 6];
b = [1 2 3 4;4 5 6 7;6 7 8 9];
n=size(b,2);
aa=zeros(size(a,1),size(b,2));
aa(:,1:size(a,2))=a(:,1:size(a,2));
Result=[aa;b]
Gives:
Result =
1 2 3 0
4 5 6 0
1 2 3 4
4 5 6 7
6 7 8 9