# How to save for loop output to column vector

2 views (last 30 days)
Kaila Fredrick on 11 Oct 2021
Commented: Kaila Fredrick on 13 Oct 2021
I create a for loop and want the output to be saved in a column vector, so that each output forms a consecutive row of the vector, but I am not sure how to do this. Here is what I have so far:
% just creating the variables
fvf= 2888.7
ccm = 3*10^8*100
h = 6.63*10^-34
v1 = ccm*fvf
invAvkg = 1/(6.022*10^23)/1000
u1 = 35/36*invAvkg
k = 4 * u1 * (v1^2) * pi^2
r1 = 127.5*10^-12
I1 = u1 * r1^2
B1 = hbar^2/2/I1
for JR = [0:3]
delER = (h*v1 + 2*(JR+1)*B1)/h/ccm
end
for JP = [1:3]
delEP = (h*v1 - 2*JP*B1)/h/ccm
end

David Hill on 11 Oct 2021
No loops needed, although you never defined hbar.
fvf= 2888.7;
ccm = 3*10^8*100;
h = 6.63*10^-34;
v1 = ccm*fvf;
invAvkg = 1/(6.022*10^23)/1000;
u1 = 35/36*invAvkg;
k = 4 * u1 * (v1^2) * pi^2;
r1 = 127.5*10^-12;
I1 = u1 * r1^2;
B1 = hbar^2/2/I1;
JR = 0:3;
delER = (h*v1 + 2*(JR+1)*B1)/h/ccm;
JP = 1:3;
delEP = (h*v1 - 2*JP*B1)/h/ccm;
Kaila Fredrick on 13 Oct 2021
That helps a lot; thanks!