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.

 Accepted Answer

Jan
Jan on 24 Mar 2017
Edited: Jan on 24 Mar 2017
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 Comments

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.

Sign in to comment.

More Answers (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.

Tags

Asked:

on 24 Mar 2017

Commented:

on 25 Mar 2017

Community Treasure Hunt

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

Start Hunting!