Skip to main content
Logo image

Subsection Basic Calculations

You can use the Command Window as a calculator by entering expressions and pressing Enter.
2 + 3
MATLAB displays the result using the default variable name ans. To keep a result for later, assign it to a variable (introduced next).
ans =
     5
MATLAB also includes built-in mathematical constants and functions.
pi
sin(pi/2)
ans =
    3.1416

ans =
    1

Checkpoint 4.

When you enter an expression without assigning it to a variable, how does MATLAB store the result?
  • It stores the result in the variable ans.
  • It permanently saves the result to a file.
  • It discards the result immediately.
  • It replaces the contents of the workspace.