How to use message box?

3 views (last 30 days)
Joe Smith
Joe Smith on 6 Mar 2015
Answered: Image Analyst on 6 Mar 2015
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.
plot(x,y), hold all
I want to the display whatever this y_value is in a message box on the figure. 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, not the number. Any ideas?

Accepted Answer

A Jenkins
A Jenkins on 6 Mar 2015
msgbox(sprintf('Failure is at %d',failure))
or maybe you would rather put it on the plot directly:
annotation('textbox',[.7,.1,.1,.1],'String',sprintf('Failure is at %d',failure))

More Answers (1)

Image Analyst
Image Analyst on 6 Mar 2015
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);


Find more on Graphics Object Identification in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!