MATLAB uses dynamic typing with automatic memory management. This means, you don't need to declare a matrix of a fixed size before using it - you can change it as you go along and MATLAB will dynamically allocate memory for you.
BUT it is way more efficient to allocate memory for the matrix first and then use it. But if your programs needs this kind of flexibility, go for it.
I'm guessing you need to keep appending rows to your matrix. The following code should work.
Matrix = [];
while size(Matrix,1) <= 10
Matrix = [Matrix;rand(1,2)];
end
disp(Matrix);
Here, we're dynamically reallocating the space required for Matrix
every time you add a new row. If you know beforehand, say, an upper bound on the number of rows you're going to have, you can declare Matrix = zeros(20,2)
and then insert each row into the matrix incrementally.
% Allocate space using the upper bound of rows (20)
Matrix = zeros(20,2);
k = 1;
for k = 1:10
Matrix(k,:) = rand(1,2);
end
% Remove the rest of the dummy rows
Matrix(k+1:end,:) = [];