A Beginner's Guide to Matlab
Introduction
Matlab is a power computational and visualization software, which is
widely used in the physics community. Matlab like Linux is a case
dependent langauge (e.g. exp(x) is equivalent to the exponential
function at a point x, whereas typing EXP(x) will produce an error).
Unlike Fortran, Matlab automatically creates variables when they are
needed because of this fact it is very important that variable names do
not include function names.
Tricks
ending a line with ... allows you to split a command between
multiple lines
ending a line with ; prevents the computed value from being
printed on the screen
multiple commands can occupy one line if they are seperated by a
, [comma]
tab will autocomplete a command or file name
pressing the up arrow will retrieve previous commands
Read Data From a File
- Drag file into Matlab window- This automatically intiates the
uiopen
command, which opens the user interface
- Enter data = dlmread('apple.csv, range)
- range = [1 1 2633 4]
- load('apple.csv',',')
NOTE: .csv is a common suffix for a file of comma seperated variables
Commands
whos-lists
all variables
clear-clears
all variables [clear a- clears variable named
a]
pwd-
prints where you are
ls-
lists files in a directory (can use wildcards *.m)
cd-
changes directory (cd .. up one, cd ~ home)
Miscellaneous
pi and i are predefined variable names
|