Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
callback function for a button

Subject: callback function for a button

From: Alex Ter-Sarkissov

Date: 14 Sep, 2010 07:03:07

Message: 1 of 4

hi, the problem is hopefully quite basic, but I couldn't crack it over the past coupla days...

In the GUI I have a button (But1) and a static text box (Tbox1). At the click of But1 the function takes some variables and computes a new variable, say s1. I want this variable to be displayed in Tbox1. So what I do is

<create function>
function prod1 (x, y)
x*y

<at the click of Bu1>
s1=prod1(5,4)
set(handles.Tbox1,'String', s1);
~or also~
set(handles.Tbox1,'string', string2double(s1))

The error message I get is 'Too many output arguments', which is quite strange, because in Command Window the answer is displayed.

thnx 4 the help

Subject: callback function for a button

From: Steven_Lord

Date: 14 Sep, 2010 13:39:22

Message: 2 of 4



"Alex Ter-Sarkissov" <ater1980@gmail.com> wrote in message
news:i6n6nb$ro4$1@fred.mathworks.com...
> hi, the problem is hopefully quite basic, but I couldn't crack it over the
> past coupla days...
>
> In the GUI I have a button (But1) and a static text box (Tbox1). At the
> click of But1 the function takes some variables and computes a new
> variable, say s1. I want this variable to be displayed in Tbox1. So what I
> do is
> <create function>
> function prod1 (x, y)
> x*y
>
> <at the click of Bu1>
> s1=prod1(5,4)

You're calling the prod1 function with two input arguments and one output
argument.

How many input and output arguments does the function declaration line for
prod1 state that it accepts?

*snip*

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: callback function for a button

From: Alex Ter-Sarkissov

Date: 14 Sep, 2010 22:06:04

Message: 3 of 4


> You're calling the prod1 function with two input arguments and one output
> argument.
>
> How many input and output arguments does the function declaration line for
> prod1 state that it accepts?
>
> *snip*
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

two input, one output, if i got yr question right. I don't know though what it means for a function declaration to 'accept' an argument.

The output is displayed in Command window, but not the widget (static text).

Subject: callback function for a button

From: Steven_Lord

Date: 15 Sep, 2010 14:14:20

Message: 4 of 4



"Alex Ter-Sarkissov" <ater1980@gmail.com> wrote in message
news:i6orkc$4bl$1@fred.mathworks.com...
>
>> You're calling the prod1 function with two input arguments and one output
>> argument.
>>
>> How many input and output arguments does the function declaration line
>> for prod1 state that it accepts?
>>
>> *snip*
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>> comp.soft-sys.matlab (CSSM) FAQ:
>> http://matlabwiki.mathworks.com/MATLAB_FAQ
>> To contact Technical Support use the Contact Us link on
>> http://www.mathworks.com
>
> two input,

Correct.

> one output,

Incorrect. Does your function declaration line look like this, which is
what the declaration line for a function with two input arguments and one
output argument should look like?

function nameOfOutput1 = prod1(nameOfInput1, nameOfInput2)

No, it does not. How many output arguments does prod1's function
declaration line indicate that prod1 returns? [Your answer should be an
integer value greater than or equal to 0, and I've already told you that 1
is not the right answer.]

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us