MATLAB Documentation for OOP
(For reference by students)


 

ASSIGNIN
Definition

Assigns a variable in workspace.
ASSIGNIN(WS,'name',V) assigns the variable 'name' in the
workspace WS the value V. WS can be one of 'caller' or 'base'.

Whenever you change the data contained in an object, assignin(...) must be used to force the changes you actually made in your local copy of the object back into the caller's copy.

This puts some restrictions on calling methods that expect to change the content of an object. The object must be supplied to the method call as a simple variable reference, rather than a Cell array or structure reference that assignin(...) cannot decipher to update the object. 
 

Example
function setBalance(acct, amount)
        acct.balance = amount;
        assignin('caller', inputname(1), acct);

ASSIGNIN in this method assigns the new balance to the object acct. Without it, the balance will not be modified.


Got comments\feedback\suggestions\complaints\anything whatsoever? Shoot the webmaster an email!

Website created & maintained by Shardul Bhatia and Wen Eu Cheah