From: Divya on
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?
From: Sean on
"Divya " <divs.raghavan(a)gmail.com> wrote in message <hrrmco$ne6$1(a)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');
From: Matt J on
"Divya " <divs.raghavan(a)gmail.com> wrote in message <hrrmco$ne6$1(a)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.