1. Matlab start/quit
In windows/Mac, start MATLAB by double-clicking the MATLAB icon on your desktop.
In Linux, start MATLAB by typing matlab from a terminal.
From the command window in Matlab, quit matlab by typing exit.
2. Constants, special values and number format
pi -- Ratio of circle's circumference to its diameter, π
>>pi
3.1416
NaN -- Not-a-Number
Inf -- Infinity
Number format: All numerical variables are stored in MATLAB in double precision floating-point form.
>>5
5 (it is double)
3. Strings and printing
Strings can be defined in MATLAB by simply enclosing the appropriate string of characters in single quotes such as
>> s = 'My Name'
fprintf can be used for the printing.
For example, we can print the name with fprintf() function.
>>fprintf(s)
My Name
Or, we also can use disp function to print the info you need.
>>disp(s)
My Name
4. Arithmetic operations
+ Addition
- Subtraction
* Multiplication
/ Division
^ Power
These operators can be used in scalar operations as well as the vector and matrix operations.
The simplest example is
>> 2*4+11/3^2
ans =
9.2222
5. Mathematical functions
abs (x) Absolute value
sqrt (x) Square root
sin (x) Sine
cos (x) Cosine
tan (x) Tangent
log (x) Natural logarithm
exp (x) Exponential function, ex
atan (x) Inverse tangent, or arctan
asin (x) Inverse sine, or arcsin
acos (x) Inverse cosine, or arccos
cosh (x) Hyperbolic cosine
sinh (x) Hyperbolic sine
For example:
>> sin(pi/3)
ans =
0.8660