You are on page 1of 18

# Gii thiu MATLAB

28/11/2014

## Cc hm u hot ng trn ma trn (hu nh

khng phi dng vng lp)

28/11/2014

## C y cc toolbox cho php s dng cc

thut ton chun trong nhiu lnh vc (ton thng
k, x l nh, x l tn hiu, mng n ron, h
thng thng tin ...)

ging dy

28/11/2014

## To mt ma trn magic vung vi tng chiu dc, ngang,

cho l bng nhau v gn kt qu ma trn 3x3 vo bin a
>> a = magic(3)
a =

8 1 6
3 5 7
4 9 2

## Php gn hoc cc quy trnh con thng kt thc vi du

chm phy, nu khng c th MATLAB s in tng kt qu.

ans

28/11/2014

## Phm Vit Hng - Nhp mn x l nh

Khi to chui

>> 11:14
ans =
11 12
>> -1:1
ans =
-1

13

14

>> 1:3:12
ans =
1 4

10

>> 4:-1:1
ans =
4 3

>> 3:0
ans =
Empty matrix:1-by-0

28/11/2014

>> 3:-0.5:2
ans =
3.0000

2.5000

2.0000

## Phm Vit Hng - Nhp mn x l nh

Mt trong ma trn l
a(2,3) == 7

ct tng ng.

## C th s dng bin end ch ra hng v ct cui

trong ma trn
a(end,end-1) == 9

chn c hng hoc ct

28/11/2014

## Phm Vit Hng - Nhp mn x l nh

Chn hng v ct
>> a(1,:)
ans =
8 1

>> a(:,1)
ans =
8
3
4
>> a(2:3,1:2)
ans =
3 5
4 9
28/11/2014

C th dng nh l vector
>> a(1:5)
ans =
8 3

>> a(6:end)
ans =
9 6 7

>> b = a(1:4:9)
b =
8 5 2
>> size(b)
ans =
1 3

## S dng [ ] to nn ma trn mi vi , hoc l phn

cch ngang v ; l phn cch dc
>> c[2 7;3 1]
c =
2 7
3 1
>> a[a(:,end) a(1,:)]
ans =
6 8
7 1
2 6
>> e = [zeros(1,3);a(2,:)]
e =
0 0 0
3 5 7
28/11/2014

>> find(a>5)
ans =
1
6
7
8
>> a(find(a>5))=0
a =
0 1 0
3 5 0
4 0 2

Ma trn mt n
Phm Vit Hng - Nhp mn x l nh

Cc php tnh
>> [1,1;1,0] * [2 3]
ans =
5
2
>> [1 2 3] .* [10 10 15]
ans =
10 20 45
>> [1 2 3] + 2
ans =
3 4 5
>> [1 2 3] + 2
ans =
3 4 5
28/11/2014

## Nhn trong v ngoi

>> [2 3 5] * [1 7 11]
ans =
78
>> [2 3 5] * [1 7 11]
ans =
2 14 22
3 21 33
5 35 55

## To ra ma trn vi lnh ngn nht

6
7
1 2 3 4 5

B = 9 7 5 3 1 1 3
4 8 16 32 64 128 256

Tnh
Tng ca ct 5 v 7

## Vector dng cui ca B

Mt phin bn ca B vi row 2 v 3 i ch
28/11/2014

10

## a ra mt php nhn vector to ra

1 2 3 4 5

a = 1 2 3 4 5
1 2 3 4 5

1
b = 2

3
4

28/11/2014

0 0

1 1
2 2

3 3
4 4
Phm Vit Hng - Nhp mn x l nh

11

x = -pi:.1:pi;

y = sin(x);
plot(x,y)

28/11/2014

## Phm Vit Hng - Nhp mn x l nh

12

plot(sin(x));
% hold axes and all lineseries properties, such as

## % ColorOrder and LineStyleOrder, for the next plot

hold all
plot(sin(x+(pi/4)));

28/11/2014

## Phm Vit Hng - Nhp mn x l nh

13

t = 0:pi/50:10*pi;

plot3(sin(t),cos(t),t)
xlabel('sin(t)')
ylabel('cos(t)')
zlabel('t')
grid on
axis square

28/11/2014

14

## bnh ca ma trn vit vo file average.m nhng

dng sau:
function y = average(x)
if ~isvector(x)
error('Input must be a vector')
end
y = sum(x)/length(x);

28/11/2014

15

## Hm stat trong stat.m tr v gi tr trung bnh v

lch chun
function [m,s] = stat(x)
n = length(x);
m = sum(x)/n;
s = sqrt(sum((x-m).^2/n));

28/11/2014

## Phm Vit Hng - Nhp mn x l nh

16

Ch c hm c cng tn vi file mi c th c

gi t bn ngoi, cc hm khc l hm ni b.

## M-file c th ch c danh sch cc hm c gi

theo th t thay v nh ngha mt hm, file ny
ch cn gi theo tn.

28/11/2014

## Phm Vit Hng - Nhp mn x l nh

17

http://www.mathworks.com/access/helpdesk/help/

helpdesk.html