Hello, when I input the following line of code into the Matlab command window: h = uicontrol('style', 'pushbutton', 'string', 'Hello', 'position', [20 150 100 70],'callback', 'disp("Hello World")');
it seems to work because a user interface comes up with no initial error with a button that has the words Hello World on it. But then when I press the button I get the following error:
??? Error using ==> disp("Hello World") Error: The input character is not valid in MATLAB statements or expressions.
??? Error while evaluating uicontrol Callback
What could I be doing wrong? I got the simple callback example from a Matla basic GUI Programming manual.
Thanks for any suggestions.

 採用された回答

Paulo Silva
Paulo Silva 2011 年 4 月 12 日

0 投票

h = uicontrol('style', 'pushbutton', 'string', 'Hello', 'position',...
[20 150 100 70],'callback', 'disp(''Hello World'')');

2 件のコメント

Oleg Komarov
Oleg Komarov 2011 年 4 月 12 日
@melissa: the difference is in the single apostrophe repeated twice.
melissa
melissa 2011 年 4 月 12 日
Thank you Paulo and Oleg so much. I would have never caught that! I knew it had to be something simple but I've never heard of a single appostrophe being used twice to display text instead of quotation marks, so I didn't even think about that.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Interactive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by