# Saving for loop output ever iteration to plot graph

2 views (last 30 days)
Ege Çetiner on 31 Mar 2021
Commented: Ege Çetiner on 1 Apr 2021
clc;
clear;
N=0;
for sCT=0.0001:0.0001:0.0038;
%sF=steel force
%sCT=strain top concrete
for c=0.1:0.01:500;
%sS=strain steel
sS1= (sCT*(abs(c-50)))/c;
sS2= (sCT*(abs(c-250)))/c;
sS3= (sCT*(abs(c-450)))/c;
%sF=steel force, unit kN
sF1=sS1*200000*3*pi*15*15/1000;
if sF1>420;
sF1=420;
else
end
sF2=sS2*200000*2*pi*15*15/1000;
if sF2>420;
sF2=420;
else
end
sF3=sS3*200000*3*pi*15*15/1000;
if sF3>420;
sF3=420;
else
end
%cF=concrete force, unit kN
%TcF=Total concrete force, unit kN
%cS=concrete stress, unit MPa
%C=strain concrete
TcF=0;
for i=1:1:100;
y=(c*(i-1/2))/100;
sC=(sCT*abs(c-y))/c;
if 0<sC<=0.002;
cS=0.85*25*(2*(sC/0.002)-((sC/0.002)*(sC/0.002)));
elseif 0.002<sC<=0.0038;
cS=0.85*25-((0.15*0.85*25*(sC-0.002))/(0.0038-0.002));
else
cS=0;
end
cF=cS*500*c/100000;
TcF=TcF+cF;
end
if -1 <(sF1 + sF2 + sF3 + TcF -N) & (sF1 + sF2 + sF3 + TcF -N) <1;
TMc=0;
for i=1:1:100;
y=(c*(i-1/2))/100;
sC=(sCT*abs(c-y))/c;
if 0<sC<=0.002;
cS=0.85*25*(2*(sC/0.002)-((sC/0.002)*(sC/0.002)));
elseif 0.002<sC<=0.0038;
cS=0.85*25-((0.15*0.85*25*(sC-0.002))/(0.0038-0.002));
else
cS=0;
end
cF=cS*500*c/100000;
Mc=(cF*abs(250-y))/1000;
TMc=TMc+Mc;
end
TMc=0.2*sF1-0.2*sF3+TMc;
break;
elseif -1 <(sF1 + sF2 - sF3 + TcF -N) & (sF1 + sF2 - sF3 + TcF -N) <1;
TMc=0;
for i=1:1:100;
y=(c*(i-1/2))/100;
sC=(sCT*abs(c-y))/c;
if 0<sC<=0.002;
cS=0.85*25*(2*(sC/0.002)-((sC/0.002)*(sC/0.002)));
elseif 0.002<sC<=0.0038;
cS=0.85*25-((0.15*0.85*25*(sC-0.002))/(0.0038-0.002));
else
cS=0;
end
cF=cS*500*c/100000;
Mc=(cF*abs(250-y))/1000;
TMc=TMc+Mc;
end
TMc=0.2*sF1+0.2*sF3+TMc;
break;
elseif -1 <(sF1 - sF2 - sF3 + TcF -N) & (sF1 - sF2 - sF3 + TcF -N) <1;
TMc=0;
for i=1:1:100;
y=(c*(i-1/2))/100;
sC=(sCT*abs(c-y))/c;
if 0<sC<=0.002;
cS=0.85*25*(2*(sC/0.002)-((sC/0.002)*(sC/0.002)));
elseif 0.002<sC<=0.0038;
cS=0.85*25-((0.15*0.85*25*(sC-0.002))/(0.0038-0.002));
else
cS=0;
end
cF=cS*500*c/100000;
Mc=(cF*abs(250-y))/1000;
TMc=TMc+Mc;
end
TMc=0.2*sF1+0.2*sF3+TMc;
break;
elseif -1 <(-sF1 - sF2 - sF3 -N) & (-sF1 - sF2 - sF3 -N) <1;
TMc=-0.2*sF1+0.2*sF3;
break;
else;
end
end
K= [sCT/(c*0.001)];
plot(K,TMc);
grid on
end
Guys can u help me? i cannot save the output of loop and plot the graph.

Image Analyst on 31 Mar 2021
Index the x and y so that they're arrays, not a single scalar. Then put the call to plot outside the loops.
Ege Çetiner on 1 Apr 2021
Thank you, sir ^^

### Categories

Find more on Surface and Mesh Plots in Help Center and File Exchange

R2020b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!