variable references (_not_ parameter by ref)

variable references (_not_ parameter by ref)

Post by Mark » Fri, 28 Jan 2011 03:00:08


Hi,

Is there any way to create a variable reference in Matlab? For instance, in the example below, in the "else" part I want to avoid that matlab copies the values of variable x into y. I'd rather make y a reference to x such that every change to y is made to x too

Thanks

%%%%%%%%%%%%%%%

if strcmp(class(x), 'sym')
y = double(x);
y[idx] = somevalue;
else
y = x;
y[idx] = some_other_value;
end
 
 
 

variable references (_not_ parameter by ref)

Post by Think blue » Fri, 28 Jan 2011 03:23:32


You would have to subclass from the handle class and define all of the
operations and routines that you want to be able to apply to the variable.

I seem to recall that one of the regular contributors has a Matlab File
Exchange contribution for creating objects that act like numeric arrays;
unfortunately I do not recall the details at the moment.

There is no easy way to do what you want in Matlab.