Got Questions? Get Answers.
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:
Pass by reference

Subject: Pass by reference

From: Divya

Date: 5 May, 2010 11:56:08

Message: 1 of 3

Hey I came across a problem in my matlab code

MATLAB does not allow pass by reference. I have to pass a flag to one function.
I have jus written a psudocode for my problem. Pls help me out

Function gui1
         flag=0;
        function pushbutton1
                %this function is invoked when certain button1 gets pressed
                value of flag is supposed to get set to 1 when this
               function is invoked (PS: this is a call back function and gets invoked
               when the button is pressed)

       function run_button
               % here i will be invoking my image registration module.
                    run_button function is also a call back function
                registration(param1,param2...... flag)





The main problem here is passing by value. When the pushbutton1 is
invoked the value of flag is changed. But that change is not
reflected. Can you propose a work around solution?

Subject: Pass by reference

From: Sean

Date: 5 May, 2010 12:18:05

Message: 2 of 3

"Divya " <divs.raghavan@gmail.com> wrote in message <hrrmco$ne6$1@fred.mathworks.com>...
> Hey I came across a problem in my matlab code
>
> MATLAB does not allow pass by reference. I have to pass a flag to one function.
> I have jus written a psudocode for my problem. Pls help me out
>
> Function gui1
> flag=0;
> function pushbutton1
> %this function is invoked when certain button1 gets pressed
> value of flag is supposed to get set to 1 when this
> function is invoked (PS: this is a call back function and gets invoked
> when the button is pressed)
>
> function run_button
> % here i will be invoking my image registration module.
> run_button function is also a call back function
> registration(param1,param2...... flag)
>
>
>
>
>
> The main problem here is passing by value. When the pushbutton1 is
> invoked the value of flag is changed. But that change is not
> reflected. Can you propose a work around solution?

I don't totally understand your problem but you might want to look at:
>>setappdata(0,'flag',flag);
and
>>flag = getappdata(0,'flag');

Subject: Pass by reference

From: Matt J

Date: 5 May, 2010 16:29:08

Message: 3 of 3

"Divya " <divs.raghavan@gmail.com> wrote in message <hrrmco$ne6$1@fred.mathworks.com>...
> Hey I came across a problem in my matlab code
>
> MATLAB does not allow pass by reference. I have to pass a flag to one function.
> I have jus written a psudocode for my problem. Pls help me out
>[snip]
> The main problem here is passing by value. When the pushbutton1 is
> invoked the value of flag is changed. But that change is not
> reflected. Can you propose a work around solution?
==========

It's not really true that MATLAB disallows passing by reference. You should read the documentation on nested functions and externally-scoped variables. You might also read about handle objects in the object-oriented programming documentaion.

Tags for this Thread

No tags are associated with 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