clc
Clears the command window, but does not delete any variable
clear
Delete all variables
home
Shifts the commands up so that the cursor is at the top left of the command window (You can still access previous commands by scrolling upwards).
help *topic*
helps on a particular topic
lookfor *keyword*
Searches for keyword in all help entries
who
Lists the names of the variables defined by the user
whos
Lists detailed information about the variables defined by the user
date
Shoes the current system date
Variable and function names are case sensitive They cannot start with a number They cannot include language specific characters such as [], (), % They cannot include punctuation characters They cannot include spaces
iskeyword
Lists keywords which you cannot assign as a variable name
isvarname *variable*
Checks whether a variable name is allowed (ans=1) or not (ans=0)
We can reassign built-in function names as variable names, but be careful! (for example "sin")
format short
4 decimal places (3.1416) (default display)
format short e
4 decimal places with exponent (3.1416e+00)
format long
many decimal places (3.141592653589793)
format long e
many decimal places with exponent (3.141592653589793e+00)
format bank
2 decimal places (3.14)
format rational
small integer ratio output (355/113)
format +
gives +, - or blank
cd *path*
Changes working directory
diary
Creates a copy of all the commands issued in the workspace window, and most of the result
save *filename* *variablelist*
Saves variables in a file
load *filename*
Loads matrices from a file
quit or exit
Terminates MATLAB
what
Lists MATLAB-specific files in directory
%%
Cell mode
m-files: Files whose names end with the extension .m (scripts and functions)
Operator | Operation |
---|---|
+ |
plus |
- |
minus |
* |
matrix multiplication |
.* |
array multiplication (element wise) |
ˆ |
matrix power |
.ˆ |
array power (element wise) |
/ |
slash or right division |
\ |
backslash or left division |
./ |
right array division (element wise) |
.\ |
left array division (element wise) |
: |
colon |
' |
transpose |
Operator | Operation |
---|---|
< | less than |
<= | less than or equal to |
> | greater than |
>= | greater than or equal to |
== | equal to |
~= | not equal to |
Operator | Operation |
---|---|
& | and |
~ | not |
$\mid$ | or |
xor | exclusive or |
a:b:c
This method creates an array with values starting from a and ending at c with an increment of b.
linspace(a,b,N)
Linearly spaced vector function. This command creates an array with N values starting from a and ending at b.
logspace(a,b,N)
Logarithmically spaced vector function.
abs(x) : Finds the absolute value of x
abs(-2)
sqrt(x) : Find the square root of x
sqrt(16)
nthroot(x,n) : Finds the real nth root of x. This function will not return complex results.
nthroot(16,4)
sign(x) : Returns a value of -1 if x is less than zero, and a value of +1 if x is greater than zero
sign(-2)
sign(2)
rem(x,y) : Computes the remainder of x/y
rem(34,5)
exp(x) : Computes the value of ex, where e is the base for natural logarithms (approximately 2.7183)
exp(15)
log(x) : Computes ln(x), the natural logarithm of x (to the base e)
log(15)
log2(x) : Computes the logarithm of x to the base 2
log2(15)
log10(x) : Computes the logarithm of x to the base 10
log10(15)
reallog(x) : Computes the natural logarithm of each element in array X. Array X must contain only nonnegative real numbers.
realpow(x,y) : Raises each element of array X to the power of its corresponding element in array Y. Array X and Y must be the same size. All elements of the output array Z must be real.
realsqrt(x) : Computes the square root of each element of array X. Array X must contain only nonnegative real numbers.
round(x) : Rounds x to the nearest integer
round(15.748)
fix(x) : Rounds (or truncates) x to the nearest integer toward zero
fix(15.748)
fix(-15.748)
floor(x) : Rounds x to the nearest integer toward negative infinity
floor(15.748)
floor(-15.748)
ceil(x) : Rounds x to the nearest integer toward positive infinity
ceil(15.748)
ceil(-15.748)
factor(x) : Finds the prime factors of x
factor(18)
gcd(x,y) : Finds the greatest common divisor of x and y
gcd(12,18)
lcm(x,y) : Finds the least common multiple of x and y
lcm(12,18)
rats(x) : Represents x as a fraction
rats(3.8)
factorial(x) : Finds the value of x factorial (x!)
factorial(5)
nchoosek(x,y) : Finds the number of possible combinations of k items from a group of n items
nchoosek(15,3)
primes(x) : Finds all the prime numbers less than x
primes(8)
isprime(x) : Checks to see if x is a prime number If it is, the function returns 1; If not, it returns 0.
isprime(11)
isprime(12)
perms(v) : Returns a matrix containing all permutations of the elements of vector v. It has n! rows and n columns. If it is, the function returns 1; If not, it returns 0.
v=[2 3 7];
perms(v)
sin(x) : Finds the sine of x (expressed in radians)
sin(0)
cos(x) : Finds the cosine of x (expressed in radians)
cos(pi)
tan(x) : Finds the tangent of x (expressed in radians)
tan(pi/4)
cot(x) : Finds the cotangent of x (expressed in radians)
cot(pi/6)
sind(x) : Finds the sine of x (expressed in degrees)
sind(90)
cosd(x), tand(x), and cotd(x) function the same way as sind(x) do
asin(x) : Finds the arcsine, or inverse sine of x, where x must be between -1 and 1. The function returns an angle in radians between $\pi/2$ and $-\pi/2$
asin(-0.5)
acos(x), atan(x), and acot(x) function the same way as asin(x) do
asind(x) : Finds the inverse sine of x (expressed in degrees)
asind(1)
acosd(x), atand(x), and acotd(x) function the same way as asind(x) do
sinh(x) : Finds the hyperbolic sine of x (expressed in radians)
sinh(pi)
cosh(x), tanh(x), and coth(x) function the same way as sinh(x) do
asinh(x) : Finds the inverse hyperbolic sine of x (expressed in radians)
asinh(1)
acosh(x), atanh(x), and acoth(x) function the same way as asinh(x) do
deg2rad(x) : Converts angle units from degrees to radians
deg2rad(90)
rad2deg(x) : Converts angle units from radians to degrees
rad2deg(pi/3)