Can you do lazy typing (: = in Mathematica) in Matlab?

So, I recently migrated from Mathematica to Matlab, and although Matlab has most of the useful functions of Mathematica, I can't figure out how to do the equivalent of the Mathematica operation delayed set ': =', which assigns the variable a value in a lazy way.

For example, in Mathematica:

y = 2;

x: = y;

y = 3;

x

will give x as 3, while the only way to get the same behavior in Matlab is:

y = 2;

x = @ () (y);

y = 3;

x ()

which, given the technical answer to my question, is a rather complicated job and requires handling x as a function.

So, is there a more natural way to do this: Matlab?

EDIT:

ad-hoc , y handle, ( someclass.y). , , , .

+5
2

, MATLAB - /. , SetDelayed . , , , .

, , -, := ( , ). :

syms x y z; %#Declare x, y and z as symbolic variables
x=y+2; %#Define some value for x
f=@(x)x.^2; %#Define an anonymous function. 

f(x)

ans =

(y + 2)^2

%#Check with z
f(z)

ans =

z^2   

, f x, . x, , x=1/y f(x) x. , f / . .

f(1:5)

ans =

     1     4     9    16    25

, :=, , , , (.. , ). , MATLAB - , . :

y=z^3; %#Define y
f(x)

ans = 
(y + 2)^2 %#The definition for y is not used.

Mathematica (z^3+2)^2.

Clear[y, z, x, f]
f[x_] := x^2;
y := z^3; x := y + 2;

f[x]

Out[1]= (2 + z^3)^2

, , . , , (, C For Mathematica).

+5

:

y = 2;
x = @()(y);
y = 3;
x()

, / y ( y). , y , , , 2 not 3

, , - set/get ( )

IMO, MATLAB Mathematica , MATLAB-, ( )

+3

All Articles