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

23 views (last 30 days)
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 :(

Answers (1)

Image Analyst
Image Analyst on 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 Comments
Jason
Jason on 14 Mar 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?
Image Analyst
Image Analyst on 15 Mar 2018
Jason, simply replace 'peppers.png' by the filename of your image.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!