Saving for loop output ever iteration to plot graph

1 vue (au cours des 30 derniers jours)
Ege Çetiner
Ege Çetiner le 31 Mar 2021
Commenté : Ege Çetiner le 1 Avr 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.

Réponse acceptée

Image Analyst
Image Analyst le 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.
  5 commentaires
Image Analyst
Image Analyst le 1 Avr 2021
Modifié(e) : Image Analyst le 1 Avr 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 le 1 Avr 2021
Thank you, sir ^^

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by