Plot the line and give maximum value of y and x at which y is maximum?

조회 수: 1 (최근 30일)
RS
RS 2013년 8월 9일
In this I want to put a line passes through maximum value of y and x axis for both plots, want to know the value of x at y=0 and ymax in legend or somewhere in figure?
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 9일
In your plot, y is never equal to zero
RS
RS 2013년 8월 9일
I want to put line from maximum value of y

댓글을 달려면 로그인하십시오.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 9일
편집: Azzi Abdelmalek 2013년 8월 9일
Edit
Example
close
x=0:0.1:10;
y1=sin(x)./(x+1);
y2=sin(x-1)./(x+1);
plot(x,y1);
hold on
plot(x,y2,'r')
a=get(gca,'xlim')
[b1,idx1]=max(y1);
[b2,idx2]=max(y2);
i1=find(abs(y1)<0.01,1);
i2=find(abs(y2)<0.01,1);
plot(a,[b1 b1]);
plot(a,[b2 b2],'r');
leg1=sprintf('x=%.2f, y=ymax1=%.2f',x(idx1),b1)
leg2=sprintf('x=%.2f, y=ymax2=%.2f',x(idx2),b2)
legend({leg1,leg2})
hold off

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by