how to fined both the coordiante
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi, how can I find the coordinate on the x-axis associated with the highest (maximunm) value of y of the function?
x=[-10:0.02:10]
y=exp(-(x-1).^2./2)+3.*exp(-(x-2).^2./2)
plot(x,y)
Can someone help me to fine the point of x associated with the max of y?
Thank you!
댓글 수: 0
채택된 답변
Image Analyst
2019년 12월 28일
Use max():
x=[-10:0.02:10]
y=exp(-(x-1).^2./2)+3.*exp(-(x-2).^2./2)
plot(x,y, 'b-', 'LineWidth', 2)
grid on;
% Find the max
[yMax, indexAtMax] = max(y)
% Put a circle around the max.
hold on;
plot(x(indexAtMax), yMax, 'ro', 'MarkerSize', 12, 'LineWidth', 2);
% Draw a line from the x-axis up to the max.
line([x(indexAtMax), x(indexAtMax)], [0, yMax], 'Color', 'r', 'LineWidth', 2);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!