MATLAB: Trying to produce a 4×40 table with the values of M, T, p, A.

table

The fprintf prints 40 values for each M, T, p, and A, however when I try and produce a table with the respected values, I only get a 1×4 table at the last iteration. I want to produce a 4×40 table with the calculated values.
% Constants
gamma = 1.27;
x = (gamma - 1)/(gamma + 1);
% Initial Guesses
T = 1;
p = 1;
A = 10;
% Loop
for M = 0:.05:2
T = (1-x)/((1+(x*((M^2)-1))));
p = (T)^((x+1)/(2*x));
A = ((1+x*((M^2)-1))^(1/(2*x)))/(M);
fprintf('M %d: T=%.20f, p=%.20f\n, A=%.20f\n', M, T, p, A);
end
Table = table(M',T',p',A','variablenames',{'M','T','p','A'});

Best Answer

Try this:
% Constants
gamma = 1.27;
x = (gamma - 1)/(gamma + 1);
% Initial Guesses
T = 1;
p = 1;
A = 10;
M = 0:.05:2
% Loop starts here
for i=1:numel(M)
%you should index the variable in order to save them in each iterations to avoid overwriting.
T(i) = (1-x)./((1+(x.*((M(i).^2)-1))));
p(i) = (T(i)).^((x+1)./(2.*x));
A(i) = ((1+x.*((M(i).^2)-1)).^(1/(2.*x)))./(M(i));
fprintf('M %d: T=%.20f, p=%.20f\n, A=%.20f\n', M(i), T(i), p(i), A(i));
end
Table = table(M',T',p',A','variablenames',{'M','T','p','A'})