Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

display a message in a message box

Asked by Elysi Cochin on 4 Jan 2013

i wanted to display a message in a message box saying...

Disease identified as Tumor,

Disease identified as Cancer, etc...

Disease identified as is constant.. tumor, cancer etc will be stored in a variable named as 'DiseaseIdentified' and i'll have to get it from that variable....

i did as below... but i'm getting error.... please could someone show me how to write it....

msgbox(sprintf('Disease identified as %s',DiseaseIdentified));

2 Comments

Seban on 4 Jan 2013

Which error do you get?

Jan Simon on 4 Jan 2013

Whenever you post in the forum, that you get an error, add the complete message also. Currently an answer requires to guess what's going on, and if our guesses are wrong, an answer can be worse than no answer.

Elysi Cochin

Tags

Products

No products are associated with this question.

2 Answers

Answer by Image Analyst on 4 Jan 2013
Accepted answer

You may want to use uiwait() so the message pauses there and waits for the user, and does not keep barreling along with the rest of your code, as just a plain msgbox will.

message = sprintf('Disease identified as %s', DiseaseIdentified{1});
uiwait(warndlg(message)); % Waits, and displays exclamation point.

or, if it is normal

uiwait(helpdlg(message)); % Waits, and displays info text balloon.
uiwait(msgbox(message)); % Waits, and displays no icon at all.

1 Comment

Elysi Cochin on 5 Jan 2013

thank u all....

Image Analyst
Answer by Azzi Abdelmalek on 4 Jan 2013
Edited by Azzi Abdelmalek on 4 Jan 2013

Maybe is that what you want

msgbox(sprintf('Disease identified as %d',1));

or

DiseaseIdentified='cancer'
msgbox(sprintf('Disease identified as %s',DiseaseIdentified));

3 Comments

Elysi Cochin on 4 Jan 2013

i too did the second way but error as below....

??? Error using ==> sprintf

Function is not defined for 'cell' inputs.

Error in ==> PlantDisease>Neural_Network_pushbutton_Callback at 358

    msgbox(sprintf('Plant Disease identified as %s',DiseaseIdentified));
Seban on 4 Jan 2013

As it said, you can't use cell input in sprintf. You need to make sure DiseaseIdentified is a string.

Azzi Abdelmalek on 4 Jan 2013

Use

DiseaseIdentified={'cancer'}
msgbox(sprintf('Disease identified as %s',DiseaseIdentified{1}));
Azzi Abdelmalek

Contact us