You are on page 1of 35

MATLAB

: MATLAB




()Workspace








-m

-

: MATLAB
-1-1

Command window :
Command History :
Current Directory :
Work Space :

Start

: MATLAB

: MATLAB
Command Window :

: MATLAB
Command History :

: MATLAB
Current Directory :



. (
)


: MATLAB
Work Space :

: MATLAB
-2-1
: :
:
>> 4*25 + 6*22 + 2*99
=ans
430

: MATLAB
-2-1
: :
:

:1 ; ,
:2

;>>a=25
;>>b=22; c=99
>>d=4*a+6*b+2*c
=d
430
>>

:3
-

: MATLAB
-3-1 :

^\/,*,-,+,
:
>>5^2
=ans
25
/ \ / . \ . 56/8 8\56
.
^ > / \ * > + - :

: MATLAB
-4-1 Work space

. .

.
.
.

: MATLAB
-4-1 Work space
:
:
who whos
: save load

: MATLAB
-1-4-1

:

: clear


>> clear
>> clear a b c

: MATLAB
-2-4-1 who whos
( ) .

Bytes Class

Size

8 double array
8 double array
8 double array

: workspace

>> whos

Name
1x1
1x1
1x1

>> who
Your variables are:
abc

a
b
c
whos .

: MATLAB
-3-4-1 : save :load

save . load .
:
;>>a=5; b=4; c=7
;>>save c:\myfile.mat a c
>>clear
>>a
??? Undefined function or variable 'a
>> load c:\myfile.mat
>>a
=a
5
>>b
??? Undefined function or variable 'a
-

: MATLAB
-3-4-1 : save :load
save load :
]save [filename] [variables
]Load [filename] [variables
. matlab.mat

.

: MATLAB
-5-1 ( )Format
.
]>>Format [option
Option: short, long, short e, long e, short g, long g, hex,
+,

: MATLAB
-6-1

( 8)double :
: struct
( 4) single :
uint8
8 :
: 16 uint16
32 uint32 :
64 uint64 :
int8
8 :
int16
16 :
int32
32 :
int64
64 :

help datatypes

: MATLAB

: MATLAB
-6-1
.
:
;)a=TypeName(a
8 >> a=uint8(a); .
32 ;)>> b = uint32(345
:
. :
)>> intmin(int16
)>> intmax(int16
: uint8.

: MATLAB
-7-1


: _
: namelengthmax MATLAB
. 2006 63 .

MATLAB
. which all
varName
:
;>>This_Is_a_Variable=5
-

: MATLAB
-8-1
.
nargin
nargout

NaN
i
j

ans
pi
eps
inf

: MATLAB
-9-1
% .
>> a=5; %a is a variable
... :
>> b=a+a^2+
;3*a^3

: MATLAB
-10-1
i j :
;>>c=1-2i
;>>c=1-2j
;>>c=1-2*j

;)>>k=(-1)^(1/2
;>>c=1-2*k
:
imag

real

angle

abs

MATLAB :
-11-1
abs
acos
asin
acosh
asinh
atan
atanh

conj
exp
fix
round
gcd(x,y)
lcm(x,y)
log

log10
real
imag
rem(x,y)
sign
sqrt

: MATLAB
-12-1
start
.
demo
help
lookfor

: MATLAB
-13-1 ( )Script m

.
m.

: MATLAB
-1-13-1
.1 :
File>New>m-file
.2
.3 :
File>Save As

: MATLAB
-2-13-1

Enter .

: ( )m .
: sample1.m
% SAMPLE1: A Simple m-file
;n=10;a=2;b=4
c=n*a^3/b + 3*n*a^2/b^2+6*n*a/b^3
--------------------------------------------------------->> sample1
=c
29.3750
-

: MATLAB
-3-13-1 m
.1 ) :disp(x .
:
;>> n=10
)>>disp(n
10
)>> disp(This is a string
This is a string

: MATLAB
-4-13-1 m
.2 ) :x=input(s .
:
) n=input(Please tell me n value:
-------------------------------------------------Please tell me n value: 10
=n
10

MATLAB :
m -4-13-1
. :pause
pause
pause(n) % n seconds

:
%SAMPLE2: Enhanced Sample1
n=10;
a=input( a value= );
b=input( b value= );
c=n*a^3/b + 3*n*a^2/b^2 + 6*n*a/b^3;
disp(Please wait 5 seconds only!);pause(5);
disp(Press any key to see answer.); pause;
disp( C Value is= ); disp(c)
-

.3

: MATLAB
:1-1 x
. y
.
;y=x^3 + 3*x^2 +6*x + 6
MATLAB .
MATLAB trace.

: MATLAB
-14-1 :
:
:cd :
>>cd
C:\Matlab\Work
>>cd C:\MyDir
>>cd
C:\MyDir
:dir
:delete( ) :
>>delete sample1
-

You might also like