Create Variables

This example shows several ways to assign a value to a variable.

x = 5.71;
A = [1 2 3; 4 5 6; 7 8 9];
I = besseli(x,A);

You do not have to declare variables before assigning values.

If you do not end an assignment statement with a semicolon (;), MATLAB® displays the result in the Command Window. For example,

x = 5.71


x =

If you do not explicitly assign the output of a command to a variable, MATLAB generally assigns the result to the reserved word ans. For example,



ans =

The value of ans changes with every command that returns an output value that is not assigned to a variable.

Was this topic helpful?