Skip to main content
Logo image

Subsection Creating Variables

You create a variable using the assignment operator, written as =. The general form is
variableName = value
When MATLAB executes an assignment:
  • The expression on the right-hand side is evaluated first.
  • The resulting value is stored under the name on the left-hand side.
The variable name appears in the Workspace after the line runs.

🌌 Example 6.

Define the variables a and b with values 1 and 7.8.
a = 1
b = 7.8
After running these commands:
  • The variables a and b exist in the workspace.
  • Their values are displayed in the Command Window.
Ending a command with a semicolon suppresses output in the Command Window, but still creates the variable. This keeps intermediate calculations from cluttering your screen.
c = -0.101
d = 88;
Both variables are stored in the workspace, but only c is displayed.

Checkpoint 7.

What effect does ending a MATLAB assignment with a semicolon have?
  • The variable is not created in the workspace.
  • The variable is created, but its value is not displayed in the Command Window.
  • The variable is created with no value.
  • The assignment only applies to the current line of code.