MATLAB Answers

I want to draw graph. use 'for/while-end loop' and use 'plot' just one time

2 ビュー (過去 30 日間)
kom gaepyo
kom gaepyo 2021 年 5 月 13 日
コメント済み: kom gaepyo 2021 年 5 月 13 日
%06_Diffusion
C0 = 0.2; % wt%
Cs = 1.0;
D = 2.6e-11;
x = 0:0.1:10; % mm
x = x./1000; % meter
t1 = 10*3600;
Cxt1 = C0 + (Cs - C0) *(1-erf(x./(2*sqrt(D*t1))));
plot (x.*1000,Cxt1,'-r','Linewidth',2)
hold on
t2 = 20*3600;
Cxt2 = C0 + (Cs - C0) *(1-erf(x./(2*sqrt(D*t2))));
plot (x.*1000,Cxt2,'-g','Linewidth',2)
t3 = 40*3600;
Cxt3 = C0 + (Cs - C0) *(1-erf(x./(2*sqrt(D*t3))));
plot (x.*1000,Cxt3,'-b','Linewidth',2)
t4 = 100*3600;
Cxt4 = C0 + (Cs - C0) *(1-erf(x./(2*sqrt(D*t4))));
plot (x.*1000,Cxt4,'-k','Linewidth',2)
hold off
title('\fontname{Arial}\fontsize{24} Time Dependent Carbon Profiles')
ylabel('\fontname{Arial}\fontsize{20} Concentration(%)')
xlabel('\fontname{Arial}\fontsize{20} Distance (mm)')
legend('10 hr', '20 hr', '40 hr', '100 hr','FontSize',18)
axis ([0 10 0 1.2])
grid on
ax1 = gca;
set(ax1,'XColor','k','YColor','k','Fontname','Arial','FontSize',18)
i want to chage-> use 'for/while end loop' and use only one 'plot'

採用された回答

David Fletcher
David Fletcher 2021 年 5 月 13 日
Something like:
%06_Diffusion
clear
C0 = 0.2; % wt%
Cs = 1.0;
D = 2.6e-11;
x = 0:0.1:10; % mm
x = x./1000; % meter
indexer=1;
for factor=[10 20 40 100]
t = factor*3600;
Cxt(indexer,:) = C0 + (Cs - C0) *(1-erf(x./(2*sqrt(D*t))));
plot(x.*1000,Cxt(indexer,:),'-','Linewidth',2)
hold on
indexer=indexer+1;
end
title('\fontname{Arial}\fontsize{24} Time Dependent Carbon Profiles')
ylabel('\fontname{Arial}\fontsize{20} Concentration(%)')
xlabel('\fontname{Arial}\fontsize{20} Distance (mm)')
legend('10 hr', '20 hr', '40 hr', '100 hr','FontSize',18)
axis ([0 10 0 1.2])
grid on
ax1 = gca;
set(ax1,'XColor','k','YColor','k','Fontname','Arial','FontSize',18)
hold off
  1 件のコメント
kom gaepyo
kom gaepyo 2021 年 5 月 13 日
Thank you!!!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by