Drawing a line through the peak of the plot

11 ビュー (過去 30 日間)
Ismita
Ismita 2023 年 1 月 21 日
コメント済み: Paul 2023 年 1 月 21 日
I have a plot as follows. How can I add vertical lines through the peak points (total 3 lines here) in the plot ?
Code:
I have written the code as:
"clear all;
m = 4.48e-26; % mass of Nitrogen molecule
k = 1.38e-23; % Boltzmann Constant
p = 0:2800;
ind = 1;
for T = 300:500:1500;
% constant computation
c1 = 4*pi*(m/(2*pi*k*T))^(3/2);
c2 = m/(2*k*T);
c3 = 3*m*k*T;
u(ind,:) = c1*(p.^2.*exp(-(c2*p.^2)));
%u2(ind,:) = c1*c3*exp(-(3/2))
ind = ind+1;
end
figure(1)
plot(p,u)
xlabel('P')
ylabel('probability')
"

回答 (1 件)

Paul
Paul 2023 年 1 月 21 日
m = 4.48e-26; % mass of Nitrogen molecule
k = 1.38e-23; % Boltzmann Constant
p = 0:2800;
ind = 1;
for T = 300:500:1500;
% constant computation
c1 = 4*pi*(m/(2*pi*k*T))^(3/2);
c2 = m/(2*k*T);
c3 = 3*m*k*T;
u(ind,:) = c1*(p.^2.*exp(-(c2*p.^2)));
%u2(ind,:) = c1*c3*exp(-(3/2))
ind = ind+1;
end
figure(1)
plot(p,u)
xlabel('P')
ylabel('probability')
Find the maximum points and their corresponding indices
[maxu,index] = max(u,[],2);
Plot vertical lines at p for each index. Use the options for xline to customize color, etc.
xline(p(index(1)));
xline(p(index(2)));
xline(p(index(3)));
  2 件のコメント
Ismita
Ismita 2023 年 1 月 21 日
Thank you so much!
Could you please explain the line
"[maxu,index] = max(u,[],2);" specially max(u,[],2) meaning. I am a new user of Matlab. Thanks again.
Paul
Paul 2023 年 1 月 21 日
Check out the doc page for max. Freel free to come back if you still have questions.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by