IntroductiontoMatlab Cse802
IntroductiontoMatlab Cse802
Matlab
For CSE 802: Pattern Recognition
Feng Kang
[email protected]
Start Matlab
You
Machines
Topics
Data
structure of Matlab.
Some
Plotting
Two
of data.
examples:
Just a number: a = 1; b = 3;
Vector:
Matrix:
A = [1 2 3; 4 5 6; 7 8 9];
a single element.
a sub-matrix.
Operations on Matrix
Cell
by cell operation.
.
E.g. B = A.^2;
B= [1 4 9; 16 25 36; 49; 64; 81];
Matrix
operation.
+, -, *.
Example
if (a>3)
b=4;
end;
statements.
j=0;
for i=1:10
j = j+i;
end
Loop
while expression
statements
end
Symbolic Toolbox(1)
Declare
a symbol object.
Symbolic Toolbox(2)
Manipulate
the function.
Compute integration.
g = int(f,x, -inf, inf); result: g =s*pi^(1/2)
Gaussian distribution: f/g
There
data:
data:
Plotting
Plot
function:
on;
plot(x1, y1, LineSpec1);
plot(x2, y2, LineSpec2);
hold off;
legend(line 1, line 2, );
xlabel(description of x axis); ylabel(description of y axis);
Plotting Example
x = 1:10 ;
y = 3*x;
z = x.^2;
figure(1)
hold on;
plot(x, y, '-ro');
plot(x, z, '-b*');
hold off;
legend('y=3*x', 'z=x.^2');
xlabel('x');
ylabel('function values');
Ezplot
Mainly
Ezplot Example
figure(1)
ezplot('x^2+y^2-1',[-1,1,-1,1]);
xlabel('x');
ylabel('function values');
Example:
IRIS data:
Plot of PCA