Mark a point on graph

1 vue (au cours des 30 derniers jours)
Leonor Vieira Dias
Leonor Vieira Dias le 1 Fév 2021
Commenté : Star Strider le 1 Fév 2021
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");

Réponse acceptée

Star Strider
Star Strider le 1 Fév 2021
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 commentaires
Leonor Vieira Dias
Leonor Vieira Dias le 1 Fév 2021
that work out very well! thank you very much
Star Strider
Star Strider le 1 Fév 2021
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by