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

조회 수: 1(최근 30일)
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 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 2021년 5월 13일
Thank you!!!

댓글을 달려면 로그인하십시오.

### 범주

Find more on Graphics Objects in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by