Help with basic GUI that answers why

I'm trying to get an understanding on basic GUI stuff. As a test, I tried to make a window with a button and a static text, and upon pressing the button, the 'why' function returns an answer in the static text. To do this, I have under the function_pushbutton1_Callback the code
set(handles.whydisplay, 'string',why);
which returns the 'Too many output arguments' error. This code works with other strings, numbers, and functions that give numerical outputs. I don't understand why it doesn't work here, and what I'm missing.

 采纳的回答

Jan
Jan 2017-3-24
编辑:Jan 2017-3-24
The command why does not have output arguments. Your code is equivalent to:
str = why; % FAILS!
set(handles.whydisplay, 'string', str);
but the first line does not work. Look in the code of why.m. It starts with:
function why(n)
You see: Not output arguments. Therefore the problem does not concern the GUI, but the handling of the function why. A workaround:
set(handles.whydisplay, 'string', evalc('why'));
or better create your clone of why.m, which replies a string as output.

2 个评论

Thanks. This works now. I hadn't noticed there was no a=why(n) or such. Now I can go ahead and make my random fantasy character name generator.
Like I suggested, Jan suggested (instead of using evalc), and even why.m itself suggested:
% Please embellish or modify this function to suit your own tastes.

请先登录,再进行评论。

更多回答(1 个)

Try editing it
>> edit why.m
Now change the first line to
function a = why(n)
Then save why.m, and try your code again.

类别

帮助中心File Exchange 中查找有关 Calendar 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by