Thread Subject: passing variables to @function

Subject: passing variables to @function

From: Johannes

Date: 24 Jan, 2008 10:30:21

Message: 1 of 2

Hi,

I've a gui with an uibuttoingroup and I want to invoke a
function when a radiobutton on the panel has been seleted.
Now what I've tried is to put the following in the create
function:

set(hObject,'SelectionChangeFcn',@selection_changed);

This works pretty well, but I want to pass some variables
along to the function. In the help I found something like

handle = @(arglist)anonymous_function

When I try to invoke the function like that

set(hObject,'SelectionChangeFcn',@(my_variable)
selection_changed);

and the function callback is like that

function selection_changed(source,eventdata, my_variable)

I get an error message. I also tried this:

function selection_changed(my_variable)

But I always get an error message. So how can I pass
variable along with the function?

Thanks for any help,
Johannes.



Subject: passing variables to @function

From: Anh Huy Phan

Date: 24 Jan, 2008 11:18:02

Message: 2 of 2

"Johannes " <RudiRocker@gmx.net> wrote in message
<fn9pbt$esb$1@fred.mathworks.com>...
> Hi,
>
> I've a gui with an uibuttoingroup and I want to invoke a
> function when a radiobutton on the panel has been seleted.
> Now what I've tried is to put the following in the create
> function:
>
> set(hObject,'SelectionChangeFcn',@selection_changed);
>
> This works pretty well, but I want to pass some variables
> along to the function. In the help I found something like
>
> handle = @(arglist)anonymous_function
>
> When I try to invoke the function like that
>
> set(hObject,'SelectionChangeFcn',@(my_variable)
> selection_changed);
>
> and the function callback is like that
>
> function selection_changed(source,eventdata, my_variable)
>
> I get an error message. I also tried this:
>
> function selection_changed(my_variable)
>
> But I always get an error message. So how can I pass
> variable along with the function?
>
> Thanks for any help,
> Johannes.
>
>
>

You can use this way

set(hObject,'SelectionChangeFcn',{@selection_changed,var1,
var2});


And your function selection_changed is defined as follow

function selection_changed(varargin)

...

In this case, you will obtain

varargin{3} - var1
varargin{4} - var2


HTH

Anh Huy Phan
RIKEN - BSI



Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
function Johannes 24 Jan, 2008 05:34:55
variables Johannes 24 Jan, 2008 05:34:55
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com