MATLAB: Display while loop output as an array

if statementloopmatlab functionwhile loop

how do you display the output of a while loop as an array.
code:
function [] = hailstone_sequence(n)
n = input('Value for n: ');
h = 1;
while(n~=1)
if n==1
return
elseif mod(n,2)
n=3*n +1
else
n=n/2
end
h=h+1;
end

Best Answer

Just before the h=h+1 insert
output(h) = n;