MATLAB: Hi i’m trying to crate a table colums of table will be col1 col2 col3 col4 and col5. I have to store all iteration steps in a matrix. How can i do that

storing all iteration reasults from for loop

clear;
clc;
syms m ;
h=6.626e-34;
k=1.3807*10^-3;
C2=14388;
C0=2.998e8;
C1=2*pi*h*C0^2;
for nlamdaT=1000:100:50000
eta=C2/nlamdaT;
fun=(6+(6*(eta*m))+(3*((m*eta).^2))+(((m*eta)^3)))/(exp(m*eta)*(m^4));
S=symsum(fun,m,1,inf);
f=(15/pi^4)*S;
% make the columns of table
col1=nlamdaT';
col2=(1/(nlamdaT))*10.^4;
col3=10^24*C1./((nlamdaT).^5.*(exp((C2./nlamdaT))-1));
col4=10^20*C1./((nlamdaT).^3.*(exp((C2./nlamdaT))-1));
col5=double(f);
nlamdaT=nlamdaT+10;
% create the table
T=table(col1,col2,col3,col4,col5)
end

Best Answer

clear; clc; syms m ;
h=6.626e-34;
k=1.3807*10^-3;
C2=14388;
C0=2.998e8;
C1=2*pi*h*C0^2;
ctr=1;
T=table;
for nlamdaT=1000:100:50000
eta=C2/nlamdaT;
fun=(6+(6*(eta*m))+(3*((m*eta).^2))+(((m*eta)^3)))/(exp(m*eta)*(m^4));
S=symsum(fun,m,1,inf); f=(15/pi^4)*S; % make the columns of table
col1(ctr)=nlamdaT';
col2(ctr)=(1/(nlamdaT))*10.^4;
col3(ctr)=10^24*C1./((nlamdaT).^5.*(exp((C2./nlamdaT))-1));
col4(ctr)=10^20*C1./((nlamdaT).^3.*(exp((C2./nlamdaT))-1));
col5(ctr)=double(f);
% T=nlamdaT+10; % NO NEEDED
x=table(col1(ctr),col2(ctr),col3(ctr),col4(ctr),col5(ctr));
T = [T; x];
ctr = ctr+1;
end
T