MATLAB: Storing user input as a vector

arrayuser input loopvector

I am asking a user for a positive number using a "while" loop. I want to store the numbers that the user gives me in a single row array and then perform several operations on the array of numbers. For example: input a number: 3 input a number: 4 input a number: 2 input a number: 2
I want an array of [3 4 2 2], but all I can get is [0 2 3 4]. I'm using
x = input ('input a number') number(x) = x
inside a while loop. Please help

Best Answer

x = zeros(1,100); %assuming no more than 100 values
cnt = 0;
while 1
cnt = cnt+1;
x(cnt) = input('d....');
if some_condition
break;
end
end
x = x(1:cnt);