Drawing a line through the peak of the plot
조회 수: 9 (최근 30일)
이전 댓글 표시
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
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);
xline(p(index(1)));
xline(p(index(2)));
xline(p(index(3)));
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!