You are on page 1of 20

Matlab

NCKU ICLab
(2017/3/6) Even

Intelligent Control Laboratory, Dept. of Engineering Science, National Cheng Kung


Command Window
MATLAB Command Window
>>
Enter

: >> (5*2+3.5)/5
ans =2.7000

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University
Command Window
MATLAB
; >> (5*2+3.5)/5;

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University
M file
MatLab
(.m) M

M file : Home New Script


: Run
:

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

63 MatLab

Ex1: c999 o

c_999 o
4c999 X
c-999 X
MATLAB

Variable Declaration
(double) 5

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

%) (comments)



: y = exp(100)/12; % y


: command window
: x=1+2+3 ...
+4;
6

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

Clc :
Clear :
clear all :
clear a b : a b

help :
lookfor
help

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

abs(x) :
acos(x) :
cos(x) : cos(x)
sqrt(x) :
log(x) :
log10(x) :
round(x) : ( )
real(x) :
imag(x) :
exp(x) :
8

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

Example 1 : y =
y = exp(-5)*(cosd(5)/asind(0.6));

Example 2 : y=sin
y = sin (30/180*pi); %(rad)
y = sind (30); %(deg)

Example 3 :
y=100^3;

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

(vector)
Example : A=[1 4 6 8 5 6];

(matrix)
Example : A= [1 2 3 ; 4 5 6 ; 7 8 9] (3x3 matrix)

10

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

min(A) :
max(A) :
sum(A) :
cumsum(A) :
prod(A) :
cumprod(A) :
sort(A) :
sort(A,'descend') :

11

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

A=[1,3,5,7,9]
A(2) :
A(2:4) :
A([2,5]) :
A(3)=100 : 100
A(3:5)=0 : 0
A(end) :
A(5)=[ ] :

12

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

Example : x=[1 2 3];
y=[1 2 4];
a=x+1 %
ans : a= 2 3 4
b=x+y %
ans : b= 2 4 7
c=x*y %
ans : c=14
:

13

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

det(A) :
inv(A) :
eig(A) :
rank(A) :
poly(A) :
expm(A) :
logm(A) :
sqrtm(A) :

14

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

eye(n,m) : nxm (n: m: )
eye(n) : nxn (n: n: )
ones(n,m) : nxm 1
ones(n) : nxn 1
zeros(n,m) : nxm 0
zeros(n) : nxn 0
rand(n,m) : nxm
rand(n) : nxn

15

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

Example : A=[1,2,3 ; 4,5,6 ; 7,8,9] => A =

A(2,2) = 5

A(2,2:3) = 5 6

A= ( )

16

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

A= [ 1 2 3 ; 4 5 6 ; 7 8 9 ] A=

B= [4 5 6 ; 7 9 9 ; 1 2 3] B=

C=A+B C=

D=A-B D=
17

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

A=[ 1 1 2 ; 2 4 -3 ; 3 6 -5] A=

B= [9 ; 1 ; 0] B=

Ax=B => x=inv(A)*B or x=A\B ( X=

xA=B => x=B*inv(A) or x=B/A ( X=B

18

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University
reference
Matlab

19

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University
Thank you for your listening.

20

Intelligent Control Laboratory, Dept. of Engineering Science,


National Cheng Kung University

You might also like