Saving for loop output ever iteration to plot graph
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Image Analyst
2021-3-31
Index the x and y so that they're arrays, not a single scalar. Then put the call to plot outside the loops.
5 个评论
Image Analyst
2021-4-1
编辑:Image Analyst
2021-4-1
You can't do stuff like
if 0<sC<=0.002
I fixed it below (I think - check it).
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 18;
fprintf('Beginning to run %s.m ...\n', mfilename);
N=0;
counter = 0;
for sCT=0.0001:0.0001:0.0038
fprintf('sCT = %.4f\n', sCT);
%sF=steel force
%sCT=strain top concrete
for c=0.1:0.01:500
%fprintf(' c = %.4f\n', c);
%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;
end
sF2=sS2*200000*2*pi*15*15/1000;
if sF2>420
sF2=420;
end
sF3=sS3*200000*3*pi*15*15/1000;
if sF3>420
sF3=420;
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) && (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) && (sC <=0.002)
cS=0.85*25*(2*(sC/0.002)-((sC/0.002)*(sC/0.002)));
elseif (0.002 < sC) && (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) && (sC <=0.002)
cS=0.85*25*(2*(sC/0.002)-((sC/0.002)*(sC/0.002)));
elseif (0.002 < sC) && (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;
end
end
K = [sCT/(c*0.001)];
% Log this point.
counter = counter + 1;
xAll(counter) = K;
yAll(counter) = TMc;
% Plot it
plot(K, TMc, 'b.', 'MarkerSize', 25);
grid on
hold on;
drawnow;
end
title('TMc vs. K', 'FontSize', fontSize);
xlabel('K', 'FontSize', fontSize);
ylabel('TMc', 'FontSize', fontSize);
% Draw lines in between the points.
plot(xAll, yAll, 'r-', 'LineWidth', 2);
hold off;
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!