It has been very difficult to use google, MATLAB documentation, I've spent a few hours, and I cannot learn how to
x = 1
y = x
x = 10
y
ans = 10
what happens instead is:
x = 1
y = x
x = 10
y
ans = 1
The value of x is stored into y. But I want to dynamically update the value of y to equal x.
What operation do I use to do this?
Thanks.M
Accepted Answer For MATLAB built-in data types, MATLAB always passes arguments 'by value' in the sense that any changes made to input arguments within a function are not visible to the respective variables in the caller workspace.
Description. varValue = getVariable( mdlWks , varName ) returns the value of the variable whose name is varName that exists in the model workspace represented by the Simulink. ModelWorkspace object mdlWks . If the value of the target variable is a handle to a handle object (such as Simulink.
Description. assignin( ws , var , val ) assigns the value val to the variable var in the workspace ws . For example, assignin('base','x',42) assigns the value 42 to the variable x in the MATLAB® base workspace.
You can also define an implicit handle on x
by defining a function on y
and referring to it:
x = 1;
y = @(x) x;
y(x) % displays 1
x = 10;
y(x) % displays 10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With