How do a custom icon to appear in the message box?

this is the error:
SWITCH expression must be a scalar or string constant.
Error in msgbox (line 120) switch(IconString)
-
when I type in the code:
myicon = imread('face.jpg');
uiwait(msgbox({'It is equal to 0!' ' ' 'Press enter to exit.'},'custom',myicon,'modal'))
-
I have the image saved in the correct file and everything, but i get the same error no matter what i do :(

Antworten (1)

Image Analyst
Image Analyst am 14 Nov. 2015
Cool! I didn't know you could use custom icons. However, the 'custom' argument must be arguemtn 3, not argument 2 like you have it. You probably didn't notice because you tried to pack too many things into one line and it became a confusing mess that is hard to maintain or understand. Try this:
rgbImage = imread('peppers.png');
myIcon = imresize(rgbImage, [64, 64]);
userPrompt = sprintf('It is equal to 0!\nClick OK to exit.\nHere is my custom icon');
msgbox(userPrompt, 'LOOK!!!', 'custom', myIcon); % Note: custom is arg 3 now!

2 Kommentare

Jason
Jason am 14 Mär. 2018
Well Image Analyst, very good answer! Thank you ,
But how can I insert an image from my computer. I think peppers.png for example are something like "built-in" images in Matlab?
Jason, simply replace 'peppers.png' by the filename of your image.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Display Image finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 13 Nov. 2015

Kommentiert:

am 15 Mär. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by