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.

 Respuesta aceptada

Jan
Jan el 24 de Mzo. de 2017
Editada: Jan el 24 de Mzo. de 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 comentarios

Thomas
Thomas el 25 de Mzo. de 2017
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.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 24 de Mzo. de 2017
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.

Categorías

Etiquetas

Preguntada:

el 24 de Mzo. de 2017

Comentada:

el 25 de Mzo. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by