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일

1 개 추천

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

Thomas
Thomas 2017년 3월 25일
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개)

Image Analyst
Image Analyst 2017년 3월 24일

2 개 추천

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에 대해 자세히 알아보기

태그

질문:

2017년 3월 24일

댓글:

2017년 3월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by