Matlab Commands

Here is a brief description of various commands. See the help or doc for more details.

ls, pwd, cd, etc.
usual Linux/Windows commands. To execute a shell command, precede it with an exclamation mark.
For example !date (note that Matlab's date has a different result than the Linux command).
computation time
to obtain the time spent doing operations expression, issue it as tic; expression; toc.
unsorted commands
Arrays
create/initialize matrices
zeros, ones, eye, diag, rand, randn, magic, etc.
size, length
array dimensions
reshape
change the way an array is arranged as a matrix
' and .'
complex conjugate and transpose, respectively only transpose, a matrix; see the help for transpose
linspace, logspace, meshgrid, etc.
produces an array of values, in one to three dimensions
Strings
Graphing
printing a graph (from octave)
if there are no mouse options/buttons can try (see How do I create a plot without a window popping up (ie, a plot to a file)?; link correct as of 2014.11)
figure
creates a new figure window, or brings the focus to the one specified. See also clf clear current figure window, gcf current figure handle (into which graphics commands like plot will draw), etc.; see the help and doc for figure
close
close windows
cla, clf
clear axes, clear figure
graph ingredients
the appearance of a graph can be adjusted either from the menus in its window, or with axis, box, xlabel, ylabel, title, legend, text, gtext, etc. The strings used in these allow TeX-like commands, for example
title('\bf Graph of \beta=\alpha_1+\alpha_{21}^3')
There are many more parameters (do get(H), where H is the handle to a figure; e.g., get(gcf) are the parameters of the current figure).
To change these parameters, use set(H, 'property1', 'value1', 'property2', 'value2', etc.). For example, set(gcf, 'name', 'Sine curves') sets the name of the current window.
subplot
puts separate graphs (axes) in the same window
ezplot, ezsurf, etc.
easy versions of the plotting commands; do lookfor easy for more such commands
fplot
plots a function on a given interval. E.g., fplot(@humps,[0 1]), fplot(@(x) sin(1./x), [0.01 0.1], 1e-3); see more in help fplot
plot
Plots functions of one variable.
Also plot3, semilogx, semilogy, loglog, plotyy, etc.; see the help for plot

Other graphical representations: bar, barh, stairs, stem, pie, hist, polar, etc.
See also fplot.

surf
Plots a function of two variables.
It can be used as surf(x,y,z) with z a matrix of size n x m and
Also surfc, surfl, contour, contour3, mesh, meshz, meshc, bar3, etc.; see the help for surf
Here is an example:
		    
[X,Y]=meshgrid(linspace(1,2,10), linspace(3,5,10));

gr=mesh(X,Y,X+Y-6,'edgecolor','green')
hold on
bl=mesh(X,Y,2*X-Y,'edgecolor','black')
alpha(gr, .5)
alpha(bl, .5)
		      
		  
The value of alpha, between 0 and 1, measures the transparency: 0=totally transparent, 1=totally opaque. See more at "help alpha".
Programming
which
Locate functions and files; it can have more arguments.
For example, which FUN1 in FUN2 displays the pathname to function FUN1 in the context of the m-file FUN2.
type
list the content of an M-file
This is an alternative to opening the file in a text-editor, after finding its location with which
if, for, while, switch/case, break, continue, return, etc.
the usual program control commands; see help matlab/lang
error
issue an error message and abort the function
eval(expression)
Evaluates a string as a Matlab expression
For example, eval(['x' '+' 'y']) is the same as x+y.

Note: it seems (but did not find documentation for this behaviour) that one can call eval with two parameters, both strings, eval(string1, string2); if the evaluation of the first string fails, the second is evaluated, if that also fails an error message is issued.
This is useful to check whether the evaluation of the first string was successful (instead of a try - catch block). Below is an example:
		    
>> eval('u*')
??? Error: Expression or statement is incomplete or incorrect.
 
>> eval('u*','3')

ans = 3

>> eval('u*','3+')
??? Error: Expression or statement is incomplete or incorrect.
 
>> test=0; eval('u+v+', 'test=1')

test = 1
		    
		  
So, in a program, where say 'input_string' is a string provided by the user, can do
		    
test=0;
eval('result=input_string','test=1');
if test==1
  % this means that eval('result=input_string') has failed
  %	so do something else
.....
end
% otherwise, continue using  result as planned
.....
		    
		  
feval(F,x1,...,xn)
Evaluates the function specified by a function handle or function name, F, at the given arguments, x1,...,xn.
For example, if F = @foo, then feval(F,9.64) or feval('foo',9.64) is the same as foo(9.64).
This is useful, e.g., if you want to pass to a subroutine a function as a parameter.
function
define a function in an M-file
by default, variables in a function M-file are local

A few related Matlab objects (check the Matlab documentation for a more precise description):
mfilename
name of currently executing M-file (as a string)
nargin
number of arguments in the function's actual call
nargout
number of function output arguments
varargin
variable length input argument list (a cell array); allows any number of arguments to a function
varargout
variable length output argument list (a cell array); allows any number of output arguments from a function
global
make a variable global
I/O, files
load
load data (or variables, if they were saved with save)
format
Change the precision used to display the results. It has many options.
E.g.,
fprintf
formated printing (similar to C); see the help, but more information is given in doc fprintf.

For example, fprintf('the values are: x = %5.2f, n = %i\n',x,n)

fopen, fclose
open/close files to read, write, append
disp
displays an array, without printing the array name
input
prompt for user input
type
list the content of an M-file
Various other commands
quad, quadl, trapz
numerical integration
round, floor, ceil, fix
roundings to integers
roots
find the roots of a polynomial (by computing the eigenvalues of the companion matrix)
fzero
find zero of a function
eig
compute eigenvalues and eigenvectors of a matrix
ode45
Integrate a vector-valued ODE, giving the vector-field, the initial condition etc. ("45" refers to the algorithm used).
dfield and pplane
these were developed by John C. Polking from Rice University
updated versions of these are at http://math.rice.edu/~dfield/

dfield plots integral curves (click on Proceed, then click in the window) for a scalar ODE, x'=f(x,t).
pplane plots integral curves (click on Proceed, then click in the window) for a system x'=f(x,y), y'=g(x,y).

There are many more features.
curve fitting
see "Basic fitting" in the "Tools" menu of a figure