How to use message box?

조회 수: 10 (최근 30일)
Joe Smith
Joe Smith 2015년 3월 6일
댓글: Image Analyst 2015년 3월 6일
I have some code that works out the y value of the first point on my graph where x>6. This is the 'failure' point.
figure
plot(x,y), hold all
failure=find(x>6,1);
I want to the display whatever this y_value is in a message box on the figure. Any ideas?

답변 (2개)

Adam
Adam 2015년 3월 6일
doc msgbox
has numerous examples. It is very simple to use, but if you have any questions after looking at that page then feel free to ask those.
  댓글 수: 2
Joe Smith
Joe Smith 2015년 3월 6일
Thanks, I've read through these but I don't understand how I can get it to display the number that 'failure=find(x>6,1);' creates.
If I did msgbox('failure') it would just display the word 'failure' in the box.
Adam
Adam 2015년 3월 6일
failNumber = find(x>6,1);
msg = ['failure: ' num2str( failNumber )];
msgbox( msg );
Or however you want to format your message.

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


Image Analyst
Image Analyst 2015년 3월 6일
Try this
% Find first element where x exceeds 6
index = find(x>6, 1, 'first');
% Get the x and y values for that index
x6 = x(index);
y6 = y(index);
% Make up a message to put on the plot:
message = sprintf('Failed at (x,y) = (%f, %f)', x6, y6);
% Place the message in a text box near the x,y point:
text(x6, y6, message, 'FontSize', 14);
  댓글 수: 1
Image Analyst
Image Analyst 2015년 3월 6일
If you want a popup message box instead of a text label sitting on your plot axes, use
uiwait(helpdlg(message));

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by