2.8. Assignment Statement

General form of an assignment statement is given as follows:

variable_name = expression;

When an assignment statement is executed, the value of the expression to the right of the equality sign is first computed and the result obtained is assigned to the variable mentioned on the left of the equality sign.

Example 2.5.

Illustrate the use of an assignment statement.

Solution:

Consider the following MATLAB statement:

y = x + 2;

To evaluate the expression (x + 2), 2 is added to the value of variable x. The result of computation is then assigned to variable y.

  • The expression to the right of the assignment operator i.e. equality sign can be any valid combination of scalars, arrays, parameters and arithmetic operators. ...

Get MATLAB® and Its Applications in Engineering: [Based on MATLAB 7.5 (R2007b)] now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.