Saving for loop output ever iteration to plot graph

1 Ansicht (letzte 30 Tage)
Ege Çetiner
Ege Çetiner am 31 Mär. 2021
Kommentiert: Ege Çetiner am 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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 31 Mär. 2021
Index the x and y so that they're arrays, not a single scalar. Then put the call to plot outside the loops.
  5 Kommentare
Image Analyst
Image Analyst am 1 Apr. 2021
Bearbeitet: Image Analyst am 1 Apr. 2021
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;
Ege Çetiner
Ege Çetiner am 1 Apr. 2021
Thank you, sir ^^

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by