Why I get this error of matrices not consistent? What's wrong?

I am trying to use that code
message = ({'Welcome, XXXXXXX';'I hope to Enjoy it' ; 'Please, share it' ; 'Cheers!'});
myicon = imread('maer.jpg');
waitfor(msgbox(message,myicon));
But I get the error
Dimensions of matrices being concatenated are not consistent.
Error in msgbox (line 182)
MsgboxTag = ['Msgbox_', TitleString];
Error in ruller (line 3)
waitfor(msgbox(message,myicon));
What matrices need to be same dimensions? The message and the image?
Following the guidelines here
Seems so easy. Please help!!

 Réponse acceptée

The icon is the 3rd input of msgbox, not the second. In fact, if you want to specify a custom icon, you've used the completely wrong syntax
I agree that the error is rather obscure, it would be better if msgbox checked that the 2nd input was valid. msgbox was expecting a one row input as the 2nd argument.
To specify a custom icon:
msgbox(message, 'some title', 'custom', myicon)

6 commentaires

That's nice and it perfectly worked.
Is there a way to adjust the size of the msgbox?
It is coming too small. I want it bigger. Since it is a welcome message screen, I'd like to have the size of almost the half of a laptop screen. Or maybe 1/3.
How I adjust the size of msgbox?
The message box is a figure like any other, so yes you can adjust its size. However, matlab automatic handling of GUI sizes is unfortunately non-existent so you will also have the adjust the size (and position) of the children of the figure as well as the font size of the text. At this point, you may as well make your own GUI.
hfig = msgbox(message, 'some title', 'custom', myicon);
hfig.Position([3 4]) = hfig.Position([3 4]) * 2; %double the size of the figure
hfig.Children(1).Position = hfig.Children(1).Position * 2; %move the button up and to the right and double its size
hfig.Children(1).FontSize = hfig.Children(1).FontSize * 2; %double the size of the text in the button
%... and so on
%hfig.Children(2) should be the axis for the icon
%hfig.Children(2).Children should be the Image object made from the icon
%hfig.Children(3) should be the axis for the text
%hfig.Children(3).Children should be the text object
When I use this line
hfig = waitfor(msgbox(message,'ACST','custom',myicon));
I get the error
Error using uiwait
Too many output arguments.
Error in ruller (line 3)
hfig = uiwait(msgbox(message,'ACST','custom',myicon));
Of course you get an error, the figure handle is the output of msgbox, not waitfor.
hfig = msgbox(message,'ACST','custom',myicon);
%code to resize figure and figure children here
%...
%after having resized it, you can call waitfor
waitfor(hfig);
Neither of those lines actually work
hfig.Children(2).myicon = hfig.Children(2).myicon *2;
hfig.Children(3).message = hfig.Children(3).message *2;
Why should they? I never suggested that.
As I said, it's probably simpler to build a GUI from scratch that is already as you want rather than resizing an existing figure and all the children.
As I said, hfig.Children(2) should be an axes. axes don't have a myicon property. The icon is the Children of that axes (so hfig.Children(2).Children). This will be an Image object. Multiplying an Image is meaningless. You would have to resize it and change its position. Possibly alter the CDataMapping property as well.
Similarly for the Text object (hfig.Children(3).Children), you'll have to change the position and FontSize property as well.
You may find it easier to find out which properties to edit in the figure hierarchy using the property editor. To get the property editor:
propertyeditor(hfig)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by