hi!
i want to write text on the plotted graph next to the min and max values of my function and i can't find it in the figure window
there is another options to find the min max values and write a text next to the graph?
thanks!
clear all
clc
t=0:0.01:2*pi;
s=1;
P=(4*sin(2.*t).*exp(-(t/s).^2)+2).*(0<=t<pi/2)+...
(4*sin(2.*t).*exp(-t/s)+2).*(pi/2<=t<=2*pi);
plot(t,P);
[a,b]=max(P);%
[c,d]=min(P);%
text(t(b),a,'maximum');%
text(t(d),c,'minimum');%
xlabel('time');
ylabel('power');
legend('p(t)');
title('power vs. time');

댓글 수: 4

Stephen23
Stephen23 2019년 7월 22일
편집: Stephen23 2019년 7월 22일
Your code works for me, what do you expect to happen?
R2012b:
untitled0.png
R2015b:
untitled1.png
ron tzuberi
ron tzuberi 2019년 7월 22일
hi!
the problem is that i can't see the text('min','max') over the graph:
‏‏לכידה.JPG
but i think madhan ravi,the guy who sent a comment after you already answer me
btw,what is the problem with my matlab?we put the same code,why doesn't my matlab show the text over the graph?
thanks!
Stephen23
Stephen23 2019년 7월 22일
@ron tzuberi: strange. What MATLAB version are you using?
ron tzuberi
ron tzuberi 2019년 7월 22일
@Stephen Cobeldick: i'm using R2018b

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

 채택된 답변

madhan ravi
madhan ravi 2019년 7월 22일

0 개 추천

t=0:0.01:2*pi;
s=1;
P=(4*sin(2.*t).*exp(-(t/s).^2)+2).*(0<=t<pi/2)+...
(4*sin(2.*t).*exp(-t/s)+2).*(pi/2<=t<=2*pi);
plot(t,P);
[a,b]=max(P);%
[c,d]=min(P);%
hold on
plot(t(b),a,'*b','MarkerSize',10)
plot(t(d),c,'*k','MarkerSize',10)
text(t(b),a,'maximum');%
text(t(d),c,'minimum');%
xlabel('time');
ylabel('power');
legend('p(t)');
title('power vs. time');

댓글 수: 1

ron tzuberi
ron tzuberi 2019년 7월 22일
hi!
thanks a lot,i think that i found the problem with your help.....
It matters where you put the line:
plot(t,P);
you put it before the lines:
text(t(b),a,'maximum');
text(t(d),c,'minimum');
thanks a lot!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2019년 7월 22일

댓글:

2019년 7월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by