Mark a point on graph

1 回表示 (過去 30 日間)
Leonor Vieira Dias
Leonor Vieira Dias 2021 年 2 月 1 日
コメント済み: Star Strider 2021 年 2 月 1 日
Hello,
I have made a graph with the following code. My goal was to know whey the y-axis is equal to 0.331. This means, the time it takes for the concentration of the lake to be 0.331. I also wanted to mark that point in my graph. Is that possible?
Thank you in advance
First, let's define our variables:
r = 10^5 ;
V = 10^10 ;
c_i = 100 ;
t = 0:10^7 ;
Then, we enter our model for the concentration in the lake :
c_L = c_i.*(1-exp((-r.*t)./V));
Finally, we plot the evolution of the concentration in the lake:
plot(t,c_L);
semilogx(c_L);
xlabel("Time t (hours)");
ylabel("Concentration of pollutant in the lake cL (kg/m^3)");
title("Concentration vs time");

採用された回答

Star Strider
Star Strider 2021 年 2 月 1 日
Try this:
r = 10^5 ;
V = 10^10 ;
c_i = 100 ;
t = logspace(-2, 7, 20);
c_L = c_i.*(1-exp((-r.*t)./V));
Q1 = nnz(diff(c_L)==0)
c_crit = 0.331;
t_crit = interp1(c_L, t, c_crit);
figure
plot(t,c_L);
hold on
plot(t_crit, c_crit, 'sr', 'MarkerFaceColor','r')
hold off
set(gca, 'XScale','log', 'YScale','log')
% semilogx(c_L);
xlabel("Time t (hours)");
ylabel("Concentration of pollutant in the lake cL (kg/m^3)");
title("Concentration vs time");
text(t_crit, c_crit, sprintf(' \\leftarrow t = %5.1f, Concentration = %6.3f', t_crit, c_crit), 'HorizontalAlignment','left', 'VerticalAlignment','middle')
Change it to produce the result you want.
  2 件のコメント
Leonor Vieira Dias
Leonor Vieira Dias 2021 年 2 月 1 日
that work out very well! thank you very much
Star Strider
Star Strider 2021 年 2 月 1 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by