TDDD34 Programming with Applications in Engineering
Commands in Matlab
Working in Matlab is not just press and go. You will need to perform certain amounts of "administration" to get going. This is a list of the most used commands to for example get help or edit a file.
All commands below must be written in Matlabs command window. You will know what that is after you read the getting started and lab introduction pages.
Create a program file (start the file editor)
To start the file editor and at the same time say that you want to use the file "assignment.m" (in current directory) to store the file you can enter any of the following two commands:
edit assignment edit assignment.m
(If you use the graphical matlab you will get the built-in editor, if you started with "matlab -nodesktop" (see getting started) you will get emacs when you issue the edit command.)
Execute a program file (*.m)
You can execute you program files by changing to the directory where it was created and entering the name of the program file. Assuming you want to run "assignment.m" created above, do:
assignment
N.B.
Matlab programs must be named with a letter as the first
character. You can not use a digit. Only use lower case when you name
files.
Useful commands
The following commands are very useful for various tasks. The items within [brackets] are keyboard shortcuts, the rest is written (or part of) commands.
[up/down arrow] Browse previous executed commands.
foo [up/down arrow] Browse previous executed commands
starting with "foo".
clc Clears the command window.
clf Clears the figure window.
who Shows all used variables.
whos Shows all used variables with more information.
help fun Shows the instruction how the function
"fun" should be used. If you do not know
the exact name of the function to get help
on, try help on a related function and look
in the "see also" part of that help page.
Chances are it contain useful suggestions
to move forward.
helpwin Same as help, but in a separate window.
... Continues a long expression on the next
line without trying to execute the first
line.
[ctrl + c] Cancel the execution of the current command.
[ctrl + i] Indent hilighted code correct.
This is done to read the code easier.
edit filname Opens a file in Matlab:s editor. The file
will be created if it do not exist.
ls, mkdir, cd Equal to the same terminal commands.
dir The windows equivalence to "ls" above.
pwd Print current working directory (the one
you last did cd to).
delete Removes a file.
copyfile Copies a file.
movefile Moves a file.
type Show the content of a file.
lookfor Search *.m files for keywords.
which Shows the path to functions and files.
save Saves variables from "workspace".
load Loads saved variables.
clear Removes variables from "workspace".
!command Executes equivalent terminal "command"
for example: !rm assignment.m
Page responsible: Erik Nilsson
Last updated: 2012-08-07
