MATLAB Variables

Variables contain statically-typed data.


Declaration

Variables are declared using the equals sign (=). To suppress printing of the value assigned, complete the declaration with a semicolon (;).

>> m=3*5

m =

    15
>> m=3*5;

Variable names must start with a letter and must contain only letters, numbers, and underscores (_). Variable names are case-sensitive.

If an interactive command tries to declare a variable with an invalid name, the prompt is re-filled where the name is replaced with a suggested 'fix'.


Workspace

Variables exist in a workspace. To clear the workspace, try clear.

To save all variables in the workspace to a file named like foo.mat, try save foo. To save a subset of variables instead, try save foo VARLIST.

To load a workspace from a file, try load foo. To load a subset of variables contained in that file, try load foo VARLIST.


CategoryRicottone