Escolar Documentos
Profissional Documentos
Cultura Documentos
Workspace
Current
DIrectory
Command
Window History
>> x = 1+2*3
x=
7
\ Division 2\3
To end your MATLAB session, type quit in the
Command Window, or select File Exit
MATLAB in the desktop main menu.
int a;
double b;
float c;
All variables are created with double precision
unless specified and they are matrices.
Example:
>>x=5;
>>x1=2;
After these statements, the variables are 1x1
matrices with double precision
Variable names ARE case sensitive
>> x = expression
expression can involve:
manual entry
built-in functions
user-defined functions
>> t = 5;
>> t = t+1
t =6
Use format command to change the output
display format for floating point numerical
>> format long
>> x =4/3
>> x = 1.333333333333333
()
4^2
*, /
+, -
>> a=7; b=cos(a), c=cosh(a)
b=
0.6570
c=
548.3170
>> a = 5; x = 2; y = 8;
>> y = exp(-a)*sin(x)+10*sqrt(y)
y=
28.2904
>> sin(pi/4)
ans =
0.7071
>> exp(10)
ans =
2.2026e+004
Syntax
length(x) Length of array
sum(x) Sum of elements in x
size(x) Dimension of matrix
sind(x) Sine of x ( x in degrees)
>>clc
Clear command window only. Memory space not cleared.
>> clear
>> clear all
removes all variables from the workspace. This frees up
system memory.
>> who
give more details which include size, space allocation,
and class of the variables.
>>ctrl+c
Abort from computation
Semicolon(;) is used to suppress the output in the
command window. It can be used when result of an
operation need not be seen directly
Commenting can be done using the % command
>> y=sqrt( 10); % taking the square root
>> help Command
>> help sqrt
x =
1 2 5 1
a matrix x = [1 2 3; 5 1 4; 3 2 -1]
x =
1 2 3
5 1 4
3 2 -1
transpose y = x y =
1
2
5
1
>> v = [1 4 7 10 13]
v=
1 4 7 10 13
>> w = [1;4;7;10;13]
w=
1
4
7
10
13
Here w=v (transpose vector)
v(1) is the first element of vector v, v(2) its
second element, and so forth
to access blocks of elements, we use
MATLAB's colon notation ( : -Range Operator)
>> v(1:3)
ans =
147
>> v(3,end)
ans =
7 10 13
>> v(:)
>> v(1:end)
begin with a square bracket, [
>> A = [1 2 3; 4 5 6; 7 8 9]
>> x=(3:0.5:6)
x= 3.0000 3.5000 4.0000 4.5000
5.0000 5.5000 6.0000
It is similar to the colon operator (:), but gives
direct control over the number of points.
y = linspace(a,b)
generates a row vector y of 100 points linearly spaced
between and including a and b.
y = linspace(a,b,n)
generates a row vector y of n points
>> y = linspace(1,10,5)
y = 1.0000 3.2500 5.5000 7.7500 10.0000
>> eye(3)
ans =
1 0 0
0 1 0
0 0 1
>> c=zeros(2,3)
c=
0 0 0
0 0 0
The element of row i and column j of the
matrix A is denoted by A(i,j).
A(1,3)=3
>> A(3,3) = 0
A=
1 2 3
4 5 6
7 8 0
>> A( : ,2)
ans =
2
5
8
>> A(2:end, : )
ans =
4 5 6
7 8 9
>> A(end-1, : )
ans =
4 5 6
To delete a row or column of a matrix, use the
empty vector operator, []
>> A(3,:) = []
A=
1 2 3
4 5 6