1.2.1: Clearing the Workspace, Readability Tips
- Page ID
Clearing the workspace
Generally, it's a good idea to use the following code when starting a MATLAB session or script file:
format compact; % Don't insert blank lines on the console--saves screen space
clear all; % Remove all previously defined variables
close all; % Close all plots (figures)
clc; % Clear the console (screen)
This example shows that you don’t have to put in spaces between numbers and operators, but spaces help readability. Try these two expressions:
1 + 2 + 3 + 4 + 5 + 6
Both expressions give the same answer.
These other arithmetic operators are clear:
2*3 - 4/5
2 raised to the 8th power is entered with the ^ symbol, called “caret”
The algebra order of operations is applied in MATLAB instructions.
Use parentheses when you need a different order of operations.
Parentheses can help readability even when not required.