Make a Plot using loop

2 ビュー (過去 30 日間)
Gyp
Gyp 2020 年 1 月 16 日
編集済み: David 2020 年 1 月 17 日
This is my code. I have to use loop, even when i dont needed to get the results. But, i have problems with the graph. I tried in different ways and the graph goes blank.I put the plot command inside the loop and out of the loop. Use other variables, use the "figure" command and nothing. If I do not use "loop" the graph goes out. But as I mentioned, I have to use the command as part of the course.
%Dg-dosage administrated(mg).
%Va-volume of distribution(L).
%Ke-absorption rate constant (h^-1).
%Ka-elimination rate constant (h^-1).
%t-time(h)since the drug was administered.
Dg=150; %mg
Vd=50; %L
Ke=0.4; %h^-1
Ka=1.6; %h^-1
for t=0:0.1:10;
disp('t= ')
disp (t)
Cp=(Dg/Vd)*(Ka/(Ka-Ke))*(exp(-Ke*t)-exp(-Ka*t));
fprintf('Cp=%g\n',Cp)
end
figure (1)
plot (t,Cp)
title ('Drug Concentration versus Time','FontName', 'Times New Roman', 'FontSize', 16)
xlabel ('time (t) ','FontName', 'Times New Roman', 'FontSize', 14)
ylabel ('Concentration (Cp) ','FontName', 'Times New Roman', 'FontSize', 14)
grid on

採用された回答

Star Strider
Star Strider 2020 年 1 月 16 日
Subscript ‘Cp’ and the plot magically appears!
Dg=150; %mg
Vd=50; %L
Ke=0.4; %h^-1
Ka=1.6; %h^-1
t=0:0.1:10;
for k = 1:numel(t)
disp('t= ')
disp (t(k))
Cp(k)=(Dg/Vd)*(Ka/(Ka-Ke))*(exp(-Ke*t(k))-exp(-Ka*t(k)));
fprintf('Cp=%g\n',Cp(k))
end
figure (1)
plot (t,Cp)
title ('Drug Concentration versus Time','FontName', 'Times New Roman', 'FontSize', 16)
xlabel ('time (t) ','FontName', 'Times New Roman', 'FontSize', 14)
ylabel ('Concentration (Cp) ','FontName', 'Times New Roman', 'FontSize', 14)
grid on
  6 件のコメント
Gyp
Gyp 2020 年 1 月 16 日
Thank you very much for the teaching.
Star Strider
Star Strider 2020 年 1 月 16 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by