You are on page 1of 108

Matlab Overview

Course Objectives
Course .

1. Matlab .
2. Matlab Installation .
3. Matlab .

Matlab
Matlab Mathworks Inc. Software.

Total Solution .
OS .
display functions .

Toolbox .
script Coding .
(e.g., C/C++, Ada etc) .
Java interpreter .
device driver .(GPIB, PCI)
CPU embedded source code .

Matlab .
Matlab
.
Matlab6.1 CD 2, Matlab6.5 CD 3 .
Full Version 1[GB] .
256[MB] .
CPU Pentium-III .
, 1[GHz] 3
.

Matlab M-file C/C++ C/C++ Compiler


. , Visual Studio .
MS Office Excel Excel.

Course Objectives
Course .

1. Matlab .
2. Matlab Installation .
3. Matlab .

Matlab Installation .
Matlab Installation .

Matlab CD Installation.
Toolbox .
Toolbox : Matlab Software
. , Library
, Library Toolbox .
Toolbox : CDMA, DSP, , etc.
Installation help CD .

Matlab6.5 3 CD toolbox pdf files


installation .

Matlab Installation .
Toolbox !
, NT OS install
.

2 help CD Install.
, 6.5 *.pdf files
3 CD .

Matlab .
Matlab6.0 Office 2000 .

: Install .
: Matlab (3,4,5) java .
website
.
Matlab6.1 .

: Window XP , Install
.
: .
Serial port Object Matlab Install
directory name _ .

Course Objectives
1. Matlab .
2. Matlab Installation .
3. Matlab .

Matlab .
Matlab6.5 software run-time
error .
Matlab work,

.
D:\matlabR12\Limspace
!

Matlab .
Matlab6.0, 6.1 .

Matlab6.5 .

Review Questions
Matlab software
?
Matlab .
, simulation ,
board device driver Application

Matlab
?

Matlab6.0 Office2000 .
Matlab6.1 Windows XP .

Summary
Matlab Fortran ,
Simulation tool. ,
JAVA 6.5 2002 9
.
Matlab
display function .
Matlab script OS .
Matlab Simulation Toolbox Image
Hardware Interface Solution .
, Xilinx, Altera EPLD vendor DSP,
HDL(Hardware Description Language) toolbox TI
DSP Code Composer Studio Application
. , Motolora DSP CPU toolbox ,
RTOS(Real Time OS) VxWorks toolbox
.

Course Objectives
Course .

1.
2.
3.
4.

Matlab Type.
Matlab .
Matlab .
.

Matlab Type.
Matlab Type .
ARRAY

char

NUMERIC

cell

struct

function handle

user class

java class
int8, uint8
int16, uint16
int32, uint32

single

double

sparse

double, char, cell, struct, function handle


.

Matlab Type.
Matlab
Type .

Matlab 2 3, 4,
.
type .
char : type.
cell, struct : C/C++ struct data type type.
function handle : Matlab6.X , matlab
pointer .
sparse :
.
int8, uint8, int16, uint16, int32, uint32 : matlab 64-bit
double precision . , bit
.

Course Objectives
Course .

1.
2.
3.
4.

Matlab Type.
Matlab .
Matlab .
.

Matlab .
>> (variable) = (expression)

index 1 .
(row) ; return key , (column) space bar
.

1 1 1

A 1 2 3
1 3 6

>>A=[1 1 1;1 2 3;1 3 6];

; , display .

2.1475e+009.

Matlab .
i, j .

>> x=1+2i; >>y=2-3j; , i, j


* .
(column) .
>>A=[1 1 1;1 2 3;1 3 6]; sumA=sum(A)
SumA =
3

10

1 1 1

A 1 2 3
1 3 6

Matlab .
transpose 2 .

A 1 2i 3 4i

A 1 2i 3 4i

>>X=[1+2i 3-4i]

>>X=[1+2i 3-4i].

1 2i

A
3 4i
1 2i

A
3 4i

Matlab .(dot)
.

Matlab .
C/C++ .
>>A=[-1.3 sqrt(3) (1+2+3)/5; exp(3) 4^2 -.145];
>>A(2,1)
ans =
20.0855

A , B
.
>>B=[4 1];

, error .
>>C=[A;B]

error matlab
.

Matlab .
: !

x=:: .
>> x=1:0.5:3;

x=
1.0000

1.5000

2.0000

2.5000

3.0000

end .
y=x(end)
y=
3

Course Objectives
Course .

1.
2.
3.
4.

Matlab Type.
Matlab .
Matlab .
.

Matlab .
Matlab 64bits double .
, format.m
.
) format rat, format hex
Matlab ,
, .
C/C++
.

Matlab , (true)
(False) :
(True) : nonzero
.
(False) : (Empty Matrix), zero

Matlab .
: ,
.

transpose( " ." ), power ( " .^ " ), transpose( "


" ), power( " ^ " )

unary plus( " + " ), unary minus( " - " )


( " * " ), ( " ./ " ), ( " . " ),

( " * " ), ( " / " ),
( " " )

( " + " ), ( " - " )


colon ( " : " )

Matlab .
: ,
(less), (not equal to) " .

Matlab .
: "AND", "OR" , TRUE",
"FALSE" .

Matlab .
(scalar) ,

.

line
.
) >>x=1+2+3+
4+5+6

Course Objectives
Course .

1.
2.
3.
4.

Matlab Type.
Matlab .
Matlab .
.

Note
, 0.234 .234 .

line .
>>x=3; y=2; z=x+y;

.
>>x=[]

[] .

format.m
.
>> format long

>> pi
ans =
3.14159265358979

Note

Review Questions
Matlab
type ?
double, char, cell, struct, function

handle

Matlab C/C++
?
Matlab index 1.

Review Questions
Matlab : ?

.
>>x=::
Matlab .
?
.^

.*

./

Review Questions
Matlab eps
?
matlab .
Matlab
?
, ,

matlab radian
degree?
radian.

Summary
Matlab
types .

type
.
. matlab .
. : .
: transpose 2 .
, , , (True)
(False) .
Matlab C/C++ ,
: .
: M-File Programming
.

Course Objectives
Course .

1.
2.
3.
4.
5.

Matlab file .
Function Mode M-file .
Script Mode M-file .
.
debugging .

Matlab file
m file .

Simulink, state flow file dynamic


link file . , *.m file
.
matlab6.X Excel toolbox , java
.
matlab6.X import wizard
file file .
matlab6.X Xilinx System generation, Altera DSP
Builder VHDL, Verilog HDL
.

Course Objectives
Course .

1.
2.
3.
4.
5.

Matlab file .
Function Mode M-file .
Script Mode M-file .
.
debugging .

Function Mode M-file .

Matlab file M-file ,


, function mode M-file, Script mode M-file .
Function Mode M-file :
function .
, . , ,
.
Function mode M-file Mfile .
function
Z=Func_name(x, y)
% Function

Function

Function Mode M-file .


>>help fact
FACT

Factorial.

Fact(n) n
factorial .
Function
workspace

, n! .

Base workspace

Function Mode M-file .


Function Mode M-file
(Local Variable). => Function workspace.
Function workspace Base Workspace
2
.
, .
(global variable) .

Function M-file matlab Compiler target


Language(, C/C++) .
Lookfor.m (Comment)
.

Course Objectives
Course .

1.
2.
3.
4.
5.

Matlab file .
Function Mode M-file .
Script Mode M-file .
.
debugging .

Script Mode M-file .


Script Mode M-file batch file.

Matlab6.X Script M-file


.

1
3

Script M-file

Script Mode M-file .


Script Mode M-file Base Workspace
.
Script M-file Matlab Compiler
.
Script Mode Function Mode M-file .

Course Objectives
Course .

1.
2.
3.
4.
5.

Matlab file .
Function Mode M-file .
Script Mode M-file .
.
debugging .

Matlab
.
if, else, elseif, end
switch, case, otherwise, end

C/C++ default otherwise .

for, end
While, end
Try, catch, end
, (true) (false)
.

.
, (true) (false)
.
switch, case if, else
program .
switch match case , case
C/C++ default
.
switch default otherwise !
for , matlab first array index 1
!
matlab C/C++ break, continue .

Course Objectives
Course .

1.
2.
3.
4.
5.

Matlab file .
Function Mode M-file .
Script Mode M-file .
.
debugging .

debugging.
, function mode m-file
function base workspace
.
Any Function M-file
function z=AnyFunc(n)
Temp=n+1;
z=Temp + 2;

function z=AnyFunc(n)
global Temp
Temp=n+1;
z=Temp + 2;

Base Workspace
Temp !

Temp !

>>Resn=10;
>>Resz=AnyFunc(Resn)
>>Temp

>>Resn=10;
>>Resz=AnyFunc(Resn)
>>global Temp
>>Temp

Review Questions
Matlab workspace
,
.
base workspace : matlab command

windows
script mode m-file
.
function workspace :

, base
workspace .

Review Questions
matlab
C/C++ ?
matlab : ~=
C/C++ : !=

matlab for, while


.
?
: (colon operator)

?
global

Summary
Matlab m-file.
m-file script mode m-file function mode m-file .
script mode m-file , function mode mfile function .
script mode m-file matlab command window
, function mode m-file ,
function .
script mode m-file function mode m-file m-file
.
script mode m-file mcc stand-alone .
,
, , , .
inline.m
.
m-file ,
,
!

Course Objectives
Course .

1. Matlab type.
2. M-file .

Matlab type.
(double) :
matlab 2, 3 .

Matlab type.
(string) :
(, ,) .
>>s=lim jong su
Matlab ASCII Code
.
>> d=double(s(1))
d=

108

Char.m

Double.m

Matlab type.
eval.m, feval.m
.
Matlab 2 type type .
cell data type : data type .
struct data type : C data type .
cell data type

Struct data type

>> A{1,1} = 1:10;

>> B.num=1:10;

>> A{1,2} = 'Jong Su';

>> B.Str='Jong Su;

Cell data type {, } !

struct data type . !

Matlab type.
matlab 6.x function handle type
.
C pointer .
function x=demo(y)

function a=FHndDemo(b)

demo

demoHnd=@demo;

a=feval(demoHnd,b);

function handle feval.m .


@ function handle
!

Course Objectives
Course .

1. Matlab type.
2. M-file .

M-file .
input.m prompt

. C scanf .
menu.m button GUI
.
matlab dialog .
helpdlg.m, inputdlg.m, pagedlg.m, printdlg.m,
errordlg.m, warndlg.m
M-file code pcode.m
.
>>pcode demo.m
pcode.m demo.m
demo.p .
! : , parsing
.

M-file .
inline.m :

inline object
type .
>> g=inline('t^2')

g=
Inline function:
g(t) = t^2

>> g(2)
ans =
4

Review Questions
Matlab
?
cell data type, struct data type
cell data type

?
{, }
cell data type
?
matlab type.

, cell data type


.

Review Questions
cellplot.m ?

cell

.
struct
?
function handle .
cell.m struct.m ?

cell data type struct data type

Review Questions
menu.m
.
.
msgbox.m
.
.
inline.m
?
function mode m-

file .

Summary
Matlab type .
double data type.

cell data type : (, ) {, }
struct data type : (, ) .
functional handle : @
inline object
type .
cell data type, struct data type
.
cell data type .
functional handle feval.m
.
matlab (dialog) .

Course Objectives
Course .

1. Handle Graphics System.


2. .
3. , .

Handle Graphics System.


matlab .

Handle Graphics System.


text Object

axes Object

figure Object

Peaks

surface Object

Handle Graphics System.


, axes object , surface object, text object
!
>>delete(gca)
axis off axes object


propertyname propertyvalue .
propertyname propertyvalue
set.m, , propertyname propertyvalue
get.m .
>>set(_handle_value, propertyname,propertyvalue)
>>Propertyvalue=get(_handle_value, propertyname)

Handle Graphics System.


propertyname position
.

figure object
figure window ,
figure object matlab desktop .

Handle Graphics System.



matlab handle value .

figure object handle value .


figure object handle
value .
handle
value .
gcf(get current figure) : figure
object handle value .
gca(get current axes) : axes
object handle value .
gco(get current object) : mouse click
object handle value .

Course Objectives
Course .

1. Handle Graphics System.


2. .
3. , .

.
matlab .
2 : plot.m, contour.m, stem.m, stairs.m, pie.m, bar.m,
etc
3 : mesh.m, surf.m, contour3.m, plot3.m, etc
: polar.m, rose.m, feather.m, compass.m, etc

: meshgrid.m, hidden on/off, legend.m,rotate3d.m etc


: cart2pol.m, pol2cart.m, cart2sph.m, sph2cart.m


handle value .
3 vector volume
visualization . [ : page 384 ]

.
plot.m :
>> t=-5:1/100:5;
>> y=1./((t-.3).^2+.01)+1./((t-.9).^2+.04)-6;
>> LnHnd=plot(t,y)
LnHnd =

3.0015
>>set(LnHnd,'color','r')

set.m
line color
.

.
LnHnd line object line object
set.m, get.m .

line object .
, x, y, z
>>set(gca,xlim,[0 inf])
Grid
>>set(gca,xgrid,on,
ygrid, on)
Figure window


>>set(gcf,color,w)

.
axes object xlim, ylim, zlim

propertyname , inf ,
inf .
matlab , axes object
.
, image, axis
equal, axis image . [ 274 ]
matlab 2 figure window
. axes object , subplot.m
.
>> x=-pi:pi/20:pi;
>> subplot(1,2,1); plot(x,cos(x),'r') % line
>> subplot(1,2,2); plot(x,sin(x),'b') % .
, figure 2 axes .

.
3 2 .
, 3 vector 3

meshgrid.m.

.
3
mesh.m .
>> [X,Y]=meshgrid(-2:.25:2);
>> Z=X.*exp(-X.^2-Y.^2);
>> mesh(X,Y,Z)

matlab 6.X figure window


bar icon click
.
,

Click , double click


, figure window

window .

.
NaN
setting .

contour.m , stem.m
discrete signal .
Figure Window menu bar View/Camera Toolbar menu
click , camera .

polar.m .
polar.m (theta,
radian) (rho) .
matlab
, X^2+y^2=3 .

.
x^2+y^2=3
matlab
. [ 402 2 ]
[ 402
2 polar.m

,

.

X^2+y^2+(z-1)^2=1
.

.
matlab 3 vector
. ,
. . 384
.
matlab animation
. comet.m
.
>> t = -pi:pi/200:pi;
>> comet(t,tan(sin(t))-sin(tan(t)))

animation line object


Erasemode propertyname .
[ 379]
.

Course Objectives
Course .

1. Handle Graphics System.


2. .
3. , .

, .
matlab file / save.m,
load.m .

save.m *.mat file , load.m


*.mat file .
>> x=magic(3); y='Lim Jong Su'; z=3+2i;

>> save DataFile x y z


, x, y, z DataFile.mat
file .
>>clear all

% base workspace .

>>load DataFile
, DataFile.mat file x, y, z
base workspace .

, .
C/C++ fopen.m, fscanf.m, fprintf.m,
fclose.m , .

Windows / dialog box .


uigetfile.m, uiputfile.m
matlab6.X file
import wizard .
matlab desktop File/Import Data menu click,
import window , ,
, import wizard window
matlab base workspace .
, clipboard ,
matlab desktop Edit/Paste Special menu click,
import wizard window .

, .
matlab excel toolbox . ,
excel link toolbox .
excel matlab excel link
toolbox excllink.xla excel
. , excel 3 icon .

, .

MS word matlab command window


notebook .

excel link, Notebook , matlab excel, MS


word memory !

Review Questions
Matlab handle value
?

.
Matlab ?
root object(Matlab desktop ).

figure object handle value


?

Review Questions
, matlab
?
text object .
universal propertyname ?

propertyname .

propertyname
?
set.m.

Review Questions
plot.m handle value
?
line object
polar.m
. ?
,

ticklabel tick , axis


off .

Review Questions
3
meshgrid.m
. meshgrid.m
?
2 , 3


mesh.m hidden
on/off ?

hidden off
.

Review Questions
surf.m shading.m
?
shading flat, shading interp

surf.m patch
object .
x
.
axes object
propertyname
?
xdir propertyname.

Review Questions
/ save.m,
load.m ?
*.mat file
import wizard
?
.
fopen.m, fclose.m
?
pointer

(fopen.m).
.(fclose.m)

Summary
matlab
.
, , handle value .
.
propertyname
propertyvalue .
set.m, get.m .
plot.m, mesh.m, polar.m
matlab .
rotate3d.m ,
camera .
NaN .
matlab mcc
stand alone .
/ save.m,
load.m , matlab6.X import wizard .
matlab excel, MS word toolbox .

Course Objectives
Course .

1. 2 .
2. .

2 .
analog digital :
Analog : .
Digital : , 0 1
.
Discrete : ,
.
Digital 0 1 bit ,
bit 8 bitsream byte . , 4
bitsream nibble .
AD Converter
Analog Signal

DA Converter

Digital Signal

2 .

2 .

Matlab .
hex2dec.m, dec2hex.m bin2dec.m, base2dec.m,
dec2base.m etc

2 .
Hardware firmware , 10
16 2 .

, 1 15 16 , .
>> A=1:15;
>> HexA=dec2hex(A)'

HexA =
123456789ABCDEF
, HexA array 16 !
16 123 2 .
>> Hex2Bin=double(dec2bin(hex2dec('123'),8))-48
Hex2Bin =
1

C , 48 .

2 .
2 .

, 0.6875 2
.

[ 464 LimDec2Bin.m 2
.
.

2 .
2 [ 465]
LimBin2Dec.m .


system
.

Computer .
, , , CPU Chip
, , , , CPU Chip
.
Maclaurin
.
2
.

2 .
computer 2
.
M=1010100, N=1000100 2 MN .

M=1010100, , 84, N=1000100, , 68. ,


M-N=16(0010000) .

8bits M, N , , 8bits
. , 10000 , 0010000
. , bit , 0,
bit MSB , 0, , 1, .
, bit LSB .

Course Objectives
Course .

1. 2 .
2. .

To be continued!

You might also like