Matlab Basic Signal

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Matlab Basic Signal as PDF for free.

More details

  • Words: 2,227
  • Pages: 25
INTRODUCTION TO MATLAB PROGRAMING

SIMPLE CALCULATION & PRECEDENCE Operators ª„ + ¨ ‡¼– * ®µ¦ / ¥„„娳Š ^

1st 2nd 3rd 4th

Precedence ªŠÁ¨È Á¦·É¤‹µ„ªŠÁ¨ÈÄœ­»—„n°œ ¥„„ε¨´Š ‹µ„Žoµ¥Åž…ªµ ‡¼–¨³®µ¦ ‹µ„Žoµ¥Åž…ªµ ª„¨³¨ ‹µ„Žoµ¥Åž…ªµ

Example 1 3^2-5-6/3*2 Ÿ 3^2-5-6/3*2 Ÿ 9-5-6/3*2 Ÿ 9-5-2*2 Ÿ 9-5-4 Ÿ 4-4 Ÿ 0 3^2-5-6/(3*2) Ÿ 3^2-5-6/(3*2) Ÿ 3^2-5-6/6 Ÿ 9-5-6/6 Ÿ 9-5-1 Ÿ 4-1 Ÿ 3

VARIABLES

• „µ¦˜´ÊŠºÉ°˜´ªÂž¦˜o°Šž¦³„°—oª¥˜´ª°´„¬¦˜´ªÁ¨È„, ˜´ª Ä®n, ˜´ªÁ¨… ®¦º° “_” ×¥˜o°Š…¹Êœ˜oœ—oª¥˜´ª°´„¬¦Ášnµœ´Êœ ¨³ ™º°ªnµ°´„¬¦˜´ªÁ¨È„¨³˜´ªÄ®n˜nµŠ„´œ • ®µ„ºÉ°˜´ªÂž¦¥µª¤µ„„ªnµ 31 ˜´ª°´„¬¦ ˜´ª°´„¬¦˜´ªš¸É 32 Áž}œ˜oœÅž‹³™¼„˜´—š·ÊŠ

VARIABLES

• ‡Îµš¸É®oµ¤œÎµ¤µ˜´ÊŠÁž}œºÉ°˜´ªÂž¦ ‡º° for, end, if, while, function, return, elseif, case, otherwise, switch, continue, else, try, catch, global, persistent, break • Ťn‡ª¦œÎµºÉ°¢{Š„r´Éœ ¨³ ˜´ªÂž¦¡·Á«¬…°Š MATLAB ¤µ˜´ÊŠÁž}œºÉ°˜´ªÂž¦ ×¥˜´ªÂž¦¡·Á«¬…°Š MATLAB ¤¸ —´Šœ¸Ê ans, beep, pi, eps, inf, NaN, nan, i, j, nargin, nargout, realmin, realmax, bitmax, varargin, varargout

SPECIAL VARIABLES ans pi

‡Îµ˜°¨nµ­»— ‡nµ‡Šš¸É S = 3.14159265358979

i,j

®œnª¥‹·œ˜£µ¡

inf

‡nµš¸ÉÁ„·—‹µ„„µ¦®µ¦—oª¥ 0 (Infinity)

NaN,nan

„µ¦‡Îµœª–š¸®É µ‡nµÅ¤nŗo (Not a Number) Ánœ 0/0 ®¦º° inf-inf

varargin

cell …°Š input argument

varargout

cell …°Š output argument

nargin

‹Îµœªœ input argument

nargout

‹Îµœªœ output argument

eps

¦´¥´®nµŠš¸Éœo°¥š¸É­»—¦´®ªnµŠ 2 ‹Îµœªœ = 2.2204e-016

realmin

˜³ªÁ¨… floating point ª„š¸œÉ o°¥š¸É­—» = 2.2251e-308

realmax

˜³ªÁ¨… floating point ª„š¸¤É µ„š¸É­—» = 1.7977e+308

bitmax

˜³ªÁ¨…‹ÎµœªœÁ˜È¤ floating point š¸¤É µ„š¸É­—» = 9.007199254740991e+015

clock

čo°„ že-Á—º°œ-ª³œ-³ÉªÃ¤Š-œµš¸-ª·œµš¸

date

ª³œš¸É Ĝ¦¼žÂ ª³œ-Á—º°œ-že

VARIABLES Example 2 tile_length = 1 tile_width = 0.5 tile_area = tile_length*tile_width floorarea = 1 FLOORAREA = 2 FloorArea = 3 TileCost_1 = (15*(floorarea/tile_area))+50 TileCost_2 = (15*(FLOORAREA/tile_area))+50 TileCost_3 = (15*(FloorArea/tile_area))+50

VARIABLES Example 3 realmax eps clock date

Example 4 pi r = 1.2

pi*(r^2)

pi*(r^2)

clear pi

pi = 3

pi

pi

pi*(r^2)

VARIABLES Example 5

Example 6

2*2+5 ans

z1 = -1+i

z1*i

-2^2;

z2 = -1+j

clear i

ans

z1*i

i

i=2

z1*i

2*ans; ans

ARRAYS & MATRICES ƒ

ƒ ƒ

„µ¦­¦oµŠ array ®¦º° Matrix Ĝ MATLAB ­µ¤µ¦™„ε®œ—Å—o—oª¥ [ ] ‡nµ¦³®ªnµŠ®¨´„‹³™¼„‡´Éœ —oª¥ space ®¦º° , „µ¦…¹ÊœÂ™ªÄ®¤n­µ¤µ¦™šÎµ ŗo—oª¥„µ¦„— Enter ®¦º° ‡´Éœ—oª¥ ;

Example 7.1 a = [1,2,3] a = [1 2 3] b = [-1;0;1] b = [-1 0 1] C = [1,0,-1;0,1,0;0,0,2] C = [1 0 -1;0 1 0;0 0 2] C = [1 0 -1 010 0 0 2]

ARRAYS & MATRICES

Array Å¨n˜ª´ Á¨…­µ¤µ¦™ „ε®œ—Å—o—Š´ œ¸Ê Start:Step:Stop ƒ Start ‡º° ‡nµ˜´ªÁ¨…Á¦·É¤˜oœ ƒ Step ‡º° ¦³¥³®nµŠ¦³®ªnµŠ ®¨´„™´—Åž„´®¨´„ž{‹‹»œ´ ƒ Stop ‡º° „µ¦„ε®œ—Ä®o‡nµ ­»—šoµ¥…°Š„µ¦Å¨n˜ª´ Á¨… Ťn Á¨¥‡nµ Stop ƒ

Example 7.2 d = 1:1:3 d = 1:3 e = 1:2:6 f = 1:2:5 g = 3:-1:1 h = 3:1

Start:Stop Ÿ Start:1:Stop

ARRAYS & MATRICES ƒ

„µ¦°oµŠ˜ÎµÂ®œnŠÄœ Array 1 ¤·˜­· µ¤µ¦™šÎµÅ—o×¥

A(index) ƒ A ‡º° ºÉ° Array ¨³ index ‡º° ˜ÎµÂ®œnŠš¸É˜o°Š„µ¦ ƒ index ­µ¤µ¦™Áž}œ Array ŗoÁ¤º°˜o°Š„µ¦°oµŠ˜ÎµÂ®œnŠ ƒ

š¸É˜°o Š„µ¦¤µ„„„ªnµ 1 ˜ÎµÂ®œnŠ „µ¦°oµŠ˜ÎµÂ®œnŠÄœ Array n ¤·˜­· µ¤µ¦™šÎµÅ—o×¥ A(index_1, index_2,…, index_n)

ARRAYS & MATRICES Example 7.3 a(1) b(2) a(end) b(end) a(end-1) a(1:2) b(3:-1:2) a([1 3]) a([1 3 2]) a([1 3 2 3]) b(2:end) b(1:end) b(:)

Example 7.4 C(3,2) C(end,2) C(end,end) C(1:2,1) C(1:2,2:3) C([1 3],[1 3]) C(1,2:end) C(1,1:end) C(1,:) C(:,1) C([1 3],:) C(:,[1 3]) C(:,:)

ARRAYS & MATRICES Example 7.5 a(1,3) b(2,1) C(:) C(5) C(end) C(1:8) C(1:end)

Example 7.6 a' [a;e] [b a'] L = [C b;a 7] L(1,1) = 5 L(2:3,2:3) = [-1 -2;-4 -6] L(end,:) = 2:2:8 L([5 10 end]) = 10 save Example_07.mat

CHARACTER ARRAYS (STRINGS) ƒ

„µ¦­¦oµŠ˜´ªÂž¦ž¦³Á£š ˜´ª°´„¬¦­µ¤µ¦™¦³»Å—o ץčo ' '

Example 8 s1 = 'DSP' s2 = ['D' 'SP'] s3 = '371' [s1 s3] ['s1' s3] s4 = 100 s5 = '100' s4+1 s5+1 s1(1) s1([1 3])

OPERATORS AND SPECIAL CHARACTERS = + * .* ^ .^ / ./ \ .\ ’ .’

„µ¦„ε®œ—‡nµ˜³ªÂž¦ ª„ ¨ ‡¼–Á¤˜¦·„Žr ‡¼–°µÁ¦¥r ¥„„娳ŠÂÁ¤˜¦·„Žr ¥„„娳ŠÂ°µÁ¦¥r ®µ¦šµŠ…ªµÂÁ¤˜¦·„Žr ®µ¦šµŠ…ªµÂ°µÁ¦¥r ®µ¦šµŠŽoµ¥ÂÁ¤˜¦·„Žr ®µ¦šµŠŽoµ¥Â°µÁ¦¥r transpose & conjugate transpose

== ~= > >= < <= & | ~ . .. …

Ášnµ„³

­—Š¨Îµ—³Äœ„µ¦‡Îµœª–

()

ŤnÁšnµ„³ ¤µ„„ªnµ

°oµŠ˜ÎµÂ®œnŠÄœÁ¤˜¦·„Žr

¤µ„„ªnµ®¦º°Ášnµ„³ œo°¥„ªnµ œo°¥„ªnµ®¦º°Ášnµ„³ ¨´ ®¦º° œ·Á­›

­—Š°·œ¡»˜Äœ¢{Š„r³Éœ

[] {} ‘ ’ , ;

: Á¦¸¥„‡nµ…°Š field Ĝ structure % parent directory čo„³ ‡Îµ­³ŠÉ cd @ ‡Îµ­³ŠÉ ˜n°Äœ¦¦š³—™³—Åž ! ‹»—š«œ·¥¤

­¦oµŠÁ¤˜¦·„Žr ­¦oµŠ®¦º°°oµŠ˜ÎµÂ®œnŠÄœ cell „ε®œ—˜³ªÂž¦ž¦´Á£š String čoÁž}œ˜³ªÂnŠ®¦º°˜³ªÂnŠ®¨³„ čoÁž}œ˜³ªÂnŠÂ™ª Ťn­—ŠŸ¨…°Š¦¦š³—œ¸Ê čo­¦oµŠ¨Îµ—³Á¨…‡–·˜ ­—Š comment ­¦oµŠ function handle Á¦¸¥„čo‡Îµ­³ŠÉ …°Š OS

OPERATORS AND SPECIAL CHARACTERS

Operator š¸¤É ¸ . °¥¼n…oµŠ®œoµ Ánœ .* ./ .\ .^ ‹³Áž}œ Array Operator Ž¹ÉŠ„µ¦‡Îµœª– ‹³šÎµ„´­¤µ·„˜ÎµÂ®œnŠ ˜n°˜ÎµÂ®œnŠ ƒ Operator š¸ÅÉ ¤n¤¸ . °¥¼n …oµŠ®œoµÁnœ * / \ ^ ‹³Áž}œ Matrix Operator Ž¹ÉŠ„µ¦ ‡Îµœª–°·Š˜µ¤®¨´„„µ¦ …°Š Matrix ƒ

Example 9 M1 = [1 2;3 4] M2 = [-2 1;-1 2] M1+M2 M1-1 2*M1 M1.*M2 M1*M2 M1./M2 M1/M2 M1.\M2 M1\M2 M1.^2 M1^2

M 1M 21 M 11M 2

GENERAL PURPOSE COMMAND help

­—Šª·›¸Äo‡Îµ­³ŠÉ ®¦º°¢{Š„r³Éœ

lookfor

‡oœ®µº°É ‡Îµ­³ŠÉ ®¦º°¢{Š„rœ³É

demo

Á¦¸¥„čo Demo

clear

¨‡nµ˜³ªÂž¦Äœ Workspace

save

³œš¹„‡nµ˜³ªÂž¦Äœ Workspace

load

—¹Š‡nµ‹µ„Å¢¨r .mat ¤µÄªoĜ Workspace ¨ Command window

clc format

„ε®œ—¦¼žÂ„µ¦Â­—ŠŸ¨…°Š˜³ªÁ¨…

warning ­—Š®¦º°Å¤n­—Š‡ÎµÁ˜º°œ beep

­nŠÁ­¸¥Š Beep

quit

°°„‹µ„ަ„¦¤ MATLAB

NUMBER DISPLAY FORMAT format short (default)

Á¨… 5 ®¨³„

3.1416

format long

Á¨… 15 ®¨³„

3.14159265358979

format short e

Á¨… 5 ®¨³„¤¸Á¨…¥„„娳Š“µœ 10

3.1416e+000

format long e

Á¨… 15 ®¨³„¤¸Á¨…¥„„娳Š“µœ 10

3.14159265358979e +000

format bank

š«œ·¥¤ 2 ®¨³„

3.14

format +

Á‡¦ºÉ°Š®¤µ¥ (+,-)

+

format hex

Á¨…“µœ 16

400921fb54442d18

format rat

Á«¬­nªœ (×¥ž¦´¤µ–)

355/113

FUNCTIONS ƒ

„µ¦Á¦¸¥„čo Function Ĝ MATLAB ­µ¤µ¦™šÎµÅ—o×¥

F(input_1, input_2,…,input_n) ƒ F ‡º° ºÉ° Function ¨³ input ‡º° ‡nµ°·œ¡»˜…°Š Function (‹Îµœªœ…°Š˜´ªÂž¦°·œ¡»˜‹³™¼„„ε®œ—×¥ Function) Example 10.1 sqrt(2)

max([1 5 6 2])

gcd(10,15)

inv([1 2;3 4])

FUNCTIONS ƒ

„µ¦„ε®œ—˜´ªÂž¦¤µ¦´‡nµ Output …°Š Function šÎµÅ—o×¥ out = F(input_1, input_2,…,input_n) [out_1,out_2,…,out_n] = F(input_1, input_2,…,input_n) [out_1 out_2 … out_n] = F(input_1, input_2,…,input_n) Example 10.2 out_a = sqrt(2)

out_c = inv([1 2;3 4])

out_b = mean([1 5 6 2])

[out_1,out_2] = size(out_c )

M-FILES ƒ ƒ ƒ

Á…¸¥œÄœÃž¦Â„¦¤ž¦³Á£š Editor ¨oª­´ÉŠÁ„ȝÁž}œÅ¢¨r Á¡ºÉ°œÎµ¤µ­´ÉŠšÎµŠµœÅ—oĜ£µ¥®¨´ŠÄœ MATLAB MATLAB ¤¸…o°´Š‡´ªnµ‹³˜o°Š¦³»œµ¤­„»¨…°ŠÅ¢¨r Áž}œ .m ¨³‹³˜o°ŠÁ„ȝŪoĜŗÁ¦„š°¦¸…°Š MATLAB ­µ¤µ¦™Á¦¸¥„ަ„¦¤Å¢¨ršÁ¸É „ȝÁž}œœ·— .m œ´ÊœÄœ ƒ ƒ

®œoµ˜nµŠ¦´‡Îµ­´ÉŠ…°Š MATLAB —oª¥„µ¦žj°œºÉ°Å¢¨rœ´Êœ¨ŠÅž ®¦º°­µ¤µ¦™Á¦¸¥„čoÅ¢¨r .m ‹µ„Å¢¨r .m °ºÉœ„Èŗo

M-FILES …o°¦³ª´Š„ȇº° ‹³˜o°Š´œš¹„Å¢¨rœ¸ÊŪoĜŗÁ¦„š°¦¸š¸É MATLAB ­µ¤µ¦™ ¤°ŠÁ®Èœ ®¦º°Á¦¸¥„ªnµ MATLAB Path Ž¹ÉŠ­µ¤µ¦™˜¦ª‹—¼Å—o‹µ„‡Îµ­´ÉŠ path ƒ ®¦º°°µ‹‹³Á„ȝŪoĜ ŗÁ¦„š°¦¸ž{‹‹»´œ…°Š Window „Èŗo Ž¹ÉŠ‹³Â­—Š °°„¤µÁ¤ºÉ°Äo‡Îµ­´ÉŠ pwd ®¦º° Tab Current Directory ƒ Ĝ„¦–¸š¸É˜o°Š„µ¦Á„ȝŪoĜŗÁ¦„š°¦¸°ºÉœ Ç „È­µ¤µ¦™Á˜·¤ºÉ°Á¡·É¤¨ŠÅž Ĝ MATLAB Path ץčo‡Îµ­´ÉŠ addpath (—¼ help addpath) ƒ

M-FILES

ƒ Script File ƒ ×¥ Script File Áž}œ»—‡Îµ­´ÉŠ

ƒ Function File ƒ Function File Áž}œ„µ¦­¦oµŠ¢{Š„r´œÄ®¤n Ž¹ÉŠ

×¥š´ÉªÅž‹³¤¸„µ¦­nŠŸnµœ‡nµ˜´ªÂž¦Á…oµ ¨³ ˜´ªÂž¦°°„

SCRIPT FILE

Á¦µ­µ¤µ¦™Á„ȝ»—‡Îµ­´ÉŠš¸Éžj°œÄ®o„´ MATLAB ŪoĜިrš¸É¤¸œµ¤­„»¨ .m ¨³­´ŠÉ Ä®o MATLAB Ş Á¦¸¥„»—‡Îµ­´ÉŠ‹µ„Å¢¨rœ¸ÊÁ­¤º°œ„´Á¦µžj°œ‡Îµ­´ÉŠ Á…oµÅžš¸¨³‡Îµ­´ÉŠÅ—o ƒ „µ¦Á¦¸¥„čoÅ¢¨rš¸Éœ ´ š¹„ŪoÁž}œ»—‡Îµ­´ÉŠš¸É Command Window ­µ¤µ¦™šÎµÅ—o×¥ ¡·¤¡rºÉ° Å¢¨rץŤn˜o°Š¤¸ .m ¨oª„— Enter ƒ

SCRIPT FILE Example 11 Editor Comment

% Find x from Ax = b clear A b x A = [1 2 3;1 0 -1;-2 3 -1]; b = [1;0;-5]; x = A\b Save as ex11.m Command Window ex11

FUNCTION FILES

Function Áž}œ m-file š¸É¤„¸ µ¦ ‘­nŠ‡nµ’ Ş¥´Š Function ¨³ ‘¦´‡nµ’ ‹µ„ Function „ Function ¤¸„µ¦¦´­nŠ‡nµ˜´ªÂž¦Å—o script ¦´­nŠ˜´ª ‡nµ˜´ªÂž¦Å¤nŗo „ Function čo˜´ªÂž¦…°Š˜´ªÁ°ŠÅ¤n¦ª¤„´ Command Window ®¦º° Function °ºœÉ Ç (˜´ªÂž¦‹³™¼„ ­¦oµŠÄ®¤nš»„‡¦´ŠÊ š¸¤É ¸„µ¦Äo Function) „

FUNCTION FILES Example 12 Editor function x = ex12(A,b) C = A^2; d = b/2 x = C\b; Save as ex12.m Command Window L=[1 2;3 4]; v = [1 ; -1]; ex12(L,v)

FUNCTION FILES Example 13 Editor function [x,y] = ex13(a,b) x = (a+b)/2; y = sqrt(a*b); Save as ex13.m Command Window ex13(5,3) [out1,out2]=ex13(5,3)

CONTROL FLOW

IF-ELSE if (condition 1) (command 1) elseif (condition 2) (command 2) . . . else (command n) end

TRY-CATCH

SWITCH-CASE switch (variable) case (value 1) (command 1) case (value 2) (command 2) . . . otherwise (command n)

try (command 1) catch (command 2) end

end

CONTROL FLOW Example 14 Editor x = input('x = '); if x == 0 disp('command 1') elseif x> 0 & x <= 3 disp('command 2') elseif x > 3 disp('command 3') elseif x >= -3 disp('command 4') else disp('command 5') end

Save as ex14.m Command Window ex14 Try x= x= x= x= x=

0 1 5 -2 -5

CONTROL FLOW Example 15 Editor

Save as ex15.m

x = input('x = ');

Command Window

switch x case 1 disp('command case {2,3} disp('command case 'abc' disp('command case {'de','f'} disp('command otherwise disp('command end

ex15 1') 2') 3') 4') 5')

Try x= x= x= x= x= x=

1 2 ‘2’ ‘a’ ‘abc’ ‘f’

CONTROL FLOW Example 16 Editor function y = ex16(x) try

y = x+[1 2 3]; catch y=0 end

Save as ex16.m Command Window ex16(1) ex16(2) ex16([1 0 1]) ex16([3 2 1]) ex16([1 2;3 4])

CONTROL FLOW

FOR LOOP

WHILE-LOOP

for (variable) (command) end

while (condition) (command) end

break

°°„‹µ„¨¼ž—oµœÄœ­»— 1 ¨¼ž

pause

®¥»—„µ¦šÎµŠµœ‹œ„ªnµ‹´¤¸„µ¦„—‡¸¥r

CONTROL FLOW Example 17 Editor n = input('n = '); s = 0; for k = 1:n s = s+k; end s

Save as ex17.m Command Window ex17 Try n= n= n= n=

3 1 0 -1

CONTROL FLOW Example 18 Editor

Save as ex18.m

n = input('n = '); s = 0; k = 1; while k <= n s = s+k; k = k+1; end s

Command Window ex18 Try n= n= n= n=

3 1 0 -1

INPUT AND OUTPUT FUNCTIONS input

­—Š˜³ª°³„¬¦Ã—¥‹´¦°°·œ¡»˜‹µ„‡¸¥r °¦r—¨oªÁ„ȝ‡nµÅªo

disp

­—Š¦µ¥¨´Á°¸¥—…°Š˜³ªÂž¦ ®¦º°…o°‡ªµ¤˜nµŠ Ç

LOGICAL FUNCTIONS xor all any find isempty exist

exclusive or ˜¦ª‹­°ªnµ­¤µ·„š»„˜³ªÅ¤nÁž}œ 0 ˜¦ª‹­°ªnµ¤¸­¤µ·„°¥nµŠœo°¥ 1 ˜³ªÅ¤nÁž}œ 0 ®µ˜ÎµÂ®œnŠš¸ÅÉ ¤nÁž}œ 0 ˜¦ª‹­°ªnµÁ¤˜¦·„Žr¤¸…œµ—Ášnµ„³ 0 ®¦º°Å¤n ˜¦ª‹­°ªnµ¤¸˜³ªÂž¦®¦º°¢{Š„r³ÉœºÉ°Á—¸¥ª„³š¸É¦´»®¦º°Å¤n

LOGICAL FUNCTIONS Example 19 all([1 1 1 1 1]) all([1 0 1 1 1]) any([1 0 0 0 0]) any([0 0 0 0 0]) A = [2 5 3 9]; all(A>1) all(A>3 & A<=10) any(mod(A,2)==0)

B = [0 0 1 1;0 1 0 1]; all(B) all(B,1) all(B,2) all(all(B)) all(B(:)) find([1 0 1 0]) find(A>3) find(B) [x,y] = find(B)

NUMERIC FUNCTIONS fix

ž{—Á¨…Ä®oÁž}œ‹ÎµœªœÁ˜È¤ ×¥ž{—Á…oµ®µ 0

floor

ž{—Á¨…Ä®oÁž}œ‹ÎµœªœÁ˜È¤ ×¥ž{—Á…oµ®µ -f

ceil

ž{—Á¨…Ä®oÁž}œ‹ÎµœªœÁ˜È¤ ×¥ž{—Á…oµ®µ +f

round

ž{—Á¨…Ä®oÁž}œ‹ÎµœªœÁ˜È¤ ×¥ž{—Á…oµ®µ‹ÎµœªœÁ˜È¤š¸ÉĄ¨oš­¸É —»

abs

®µ‡nµ­³¤¼¦–r

sign

®µÁ‡¦ºÉ°Š®¤µ¥ (+,-)

rem

®µÁ«¬‹µ„µ¦®µ¦

mod

modulo

COMPLEX NUMBER FUNCTIONS real

®µ­nªœ‹¦·Š

imag

®µ­nªœ‹·œ˜£µ¡

conj angle

®µ conjugate ®µ¤»¤Á¢­Áž}œÁ¦Á—¸¥œ

EXPONENTIAL AND LOGARITHM FUNCTIONS ®µ¦µ„š¸É 2 ¥„„娳Š“µœ e ‡nµ log “µœ e ‡nµ log “µœ 10

sqrt exp log log10

log2 sqrtm expm logm

‡nµ log “µœ 2 ®µ¦µ„š¸É 2 Á¤˜¦·„Žr ¥„„娳Š“µœ e Á¤˜¦·„Žr ‡nµ log “µœ e Á¤˜¦·„Žr

TRIGONOMETRY AND HYPERBORIC FUNCTIONS sin

sine

asin

arcsine

sinh

hyperboric sine

asinh

hyperboric arcsine

cos

cosine

acos

arccosine

cosh

hyperboric cosine

acosh

hyperboric arccosine

tan

tangent

atan

arctangent

tanh

hyperboric tangent

atanh

hyperboric arctangent

csc

cosecant

acsc

arccosecant

csch

hyperboric cosecant

acsch

hyperboric arccosecant

sec

secant

asec

sech

hyperboric secant

asech

hyperboric arcsecant

cot

cotangent

acot

arcsecant arccotangen t

coth

hyperboric cotangent

acoth

hyperboric arccotangent

°·œ¡»˜Áž}œÁ¦Á—¸¥œ STATISTICTIC FUNCTIONS min

®µ‡nµ˜Éε­»—

median

®µ¤³›¥“µœ

cumsum

®µŸ¨¦ª¤­´­¤

max

®µ‡nµ­¼Š­»—

sort

Á¦¸¥Š…o°¤¼¨

cumprod

®µŸ¨‡¼–­´­¤

range

®µ¡·­¥³

sum

®µŸ¨¦ª¤

diff

®µŸ¨˜nµŠ¦´®ªnµŠ­¤µ·„˜³ªš¸˜É ·—„³œ

mean

®µ‡nµÁŒ¨¸É¥

prod

®µŸ¨‡¼–

std

®µ­nªœÁ¸É¥ŠÁœ¤µ˜¦“µœ

STRING FUNCTIONS str2num

ž¨Š˜³ª°³„¬¦Áž}œ˜³ªÁ¨…

bin2dec

ž¨ŠÁ¨…“µœ 2 Áž}œ “µœ 10

num2str

ž¨Š˜³ªÁ¨…Áž}œ˜³ª°³„¬¦

dec2bin

ž¨ŠÁ¨…“µœ 10 Áž}œ “µœ 2

strcmp

Áž¦¸¥Áš¸¥˜³ª°³„¬¦

hex2dec

ž¨ŠÁ¨…“µœ 16 Áž}œ “µœ 10

strcmpi

Áž¦¸¥Áš¸¥˜³ª°³„¬¦ ×¥™º°ªnµ ˜³ª°³„¬¦˜³ªÁ¨È„„³˜³ªÄ®nÁ®¤º°œ„³œ

dec2hex

ž¨ŠÁ¨…“µœ 10 Áž}œ “µœ 16

base2dec

ž¨ŠÁ¨…“µœš¸„É 宜—Áž}œ “µœ 10

strfind

®µ˜ÎµÂ®œnŠ˜³ª°³„¬¦˜µ¤š¸É„ε®œ—

dec2base

ž¨ŠÁ¨…“µœ 10 Áž}œ“µœš¸„É 宜—

STATISTICTIC FUNCTIONS Example 20 A = [2 5 3 9]; min(A) max(A) mean(A) sum(A) prod(A)

B = [1 2 1 3;2 4 1 0]; min(B) min(B,1) min(B,2) min(min(B)) min(B(:))

sort(A)

sum(B) sum(B,1) sum(B,2) sum(sum(B)) sum(B(:))

diff(A)

MATRIX FUNCTIONS zeros ones eye linspace logspace

­¦oµŠÁ¤˜¦·„Žr¤¸­¤µ·„Áž}œ 0 š³ÊŠ®¤— ­¦oµŠÁ¤˜¦·„Žr¤¸­¤µ·„Áž}œ 1 š³ÊŠ®¤— ­¦oµŠÁ¤˜¦·„ŽrÁ°„¨³„¬–r ­¦oµŠÁª‡Á˜°¦r…°Š¨Îµ—³Á¨…‡–·˜ ­¦oµŠÁª‡Á˜°¦r…°Š¨Îµ—³Á¦…µ‡–·˜

length size fliplr flipud flipdim

®µ‡ªµ¤¥µª…°ŠÁ¤˜¦·„Žr ®µ…œµ—…°ŠÁ¤˜¦·„Žr „¨³Á¤˜¦·„ŽrĜš·«šµŠ Žoµ¥-…ªµ „¨³Á¤˜¦·„ŽrĜš·«šµŠ œ-¨nµŠ „¨³Á¤˜¦·„ŽrĜš·«šµŠš¸„É 宜— ®¤»œÁ¤˜¦·„Žr ±90q, ±180q,...

rand

­¦oµŠÁ¤˜¦·„Žr¤¸­¤µ·„Å—o‹µ„„µ¦­»n¤ ‡nµ 0-1 š¸É¤¸„µ¦„¦´‹µ¥Â Uniform

rot90 tril

­¦oµŠÁ¤˜¦·„Žr­µ¤Á®¨¸É¥¤¨nµŠ

triu

­¦oµŠÁ¤˜¦·„Žr­µ¤Á®¨¸É¥¤œ

randn

­¦oµŠÁ¤˜¦·„Žr¤¸­¤µ·„Å—o‹µ„„µ¦­»n¤ ‡n µ š¸É ¤¸ „ µ¦„¦´‹µ¥Â Normal ¤¸ ‡n µ ÁŒ¨¸É ¥ Áž} œ 0 ¤¸ ­n ª œÁ¸É ¥ ŠÁœ ¤µ˜¦“µœÁž}œ 1

det

®µ—¸Áš°¦r¤·Âœœšr…°ŠÁ¤˜¦·„Žr

inv

®µÁ¤˜¦·„ŽrŸ„Ÿ³œ

­¦oµŠÁ¤˜¦·„Žrš´Â¥Š Áž¨¸É¥œ…œµ—…°ŠÁ¤˜¦·„Žr

pinv

diag reshape

rank

®µÁ¤˜¦·„ŽrŸ„Ÿ³œÁ­¤º°œ ®µÂ¦Š‡r…°ŠÁ¤˜¦·„ªr

MATRIX FUNCTIONS Example 21 zeros(3,5)

B = [1 2 1 3;2 4 1 0];

ones(1,7)

length(B)

eye(5)

size(B)

diag([1 2 3 4])

reshape(B,4,2)

linspace(0,pi,20)

C = [1+i 1+2i ; 3-i 2];

rand(1,7)

C’

randn(1,7)

transpose(C)

SPARSE MATRIX FUNCTIONS sparse

­¦oµŠ sparse matrix š¸ÉÁž}œ Á¤˜¦·„Žr«¼œ¥r ®¦º° Áž¨¸É¥œ­¤µ·„Äœ˜ÎµÂ®œnŠš¸ÉŤnÁšnµ„³ 0 spones ž¨ŠÁ¤˜¦·„Žr›¦¦¤—µÁž}œ sparse matrix Ĝ sparse matrix Ä®oÁšnµ„³ 1

speye

­¦oµŠ sparse matrix š¸ÉÁž}œ Á¤˜¦·„ŽrÁ°„¨³„¬–r

full

ž¨Š sparse matrix Áž}œÁ¤˜¦·„Žr›¦¦¤—µ

SET FUNCTIONS unique union intersect

˜³—­¤µ·„˜³ªš¸ŽÉ µÊÎ „³œ°°„¡¦o°¤š³ŠÊ Á¦¸¥Š…o°¤¼¨ set union set intersection

setdiff setxor ismember

set difference set exclusive union ˜¦ª‹­°„µ¦Áž}œ­¤µ·„

POLYNOMIAL FUNCTIONS roots

®µ¦µ„…°Š¡®»œµ¤

residue

®µ partial fraction

poly

®µ¡®»œµ¤‹µ„¦µ„

polyder

®µ°œ»¡œ³ ›r…°Š¡®»œµ¤

polyval

®µ‡nµ…°Š¡®»œµ¤

polyint

®µž’·¥µœ»¡œ³ ›r…°Š¡®»œµ¤

polyfit

®µ¡®»œµ¤š¸‹É µ„‡¼n°³œ—³š¸„É 宜— (ž¦´¤µ–)

conv

‡¼–¡®»œµ¤

deconv

®µ¦¡®»œµ¤

SET FUNCTIONS

Example 22 A = [2 3 4 2 4 3 1]; B = [0 3 5 3 2];

setdiff(A,B) setdiff(B,A)

unique(A)

ismember(A,B)

union(A,B) intersect(A,B)

CELL FUNCTIONS cell

­¦oµŠ cell ªnµŠ

deal

„ε®œ—‡nµ˜³ªÂž¦Å—oš¸É¨´®¨µ¥˜³ª

iscell num2cell

˜¦ª‹­°ªnµÁž}œ˜³ªÂž¦ž¦´Á£š cell ®¦º°Å¤n ®µ°œ»¡œ³ ›r…°Š¡®»œµ¤

STRUCTURE FUNCTIONS struct

­¦oµŠ structure

isfield

˜¦ª‹­°ªnµ¤¸ºÉ° field š¸É„ε®œ—®¦º°Å¤n

isstruct

˜¦ª‹­°ªnµÁž}œ˜³ªÂž¦ž¦´Á£š structure ®¦º°Å¤n

fieldnames

Á¦¸¥„—¼ºÉ° field Ĝ structure

getfield

Á¦¸¥„‡nµ…°Š field Ĝ structure

setfield

„ε®œ—‡nµ…°Š field Ĝ structure struct2cell ž¨Š structure Áž}œ cell

rmfield

¨ field

cell2struct

ž¨Š cell Áž}œ structure

SYMBOLIC FUNCTIONS sym,syms

­¦oµŠ˜³ªÂž¦ž¦´Á£š symbolic

compose

®µ composite …°Š function

šœ‡nµ˜³ªÂž¦ symbolic

diff

®µ°œ»¡œ³ ›r

sinplify

Áž¨¸É¥œÄ®o°¥¼nĜ¦¼žš¸­É œ³Ê š¸­É —»

int

®µž‘·¥µœ»¡œ³ ›r

expand

„¦´‹µ¥¡‹œr°°„¤µ

limit

numden

®µÁ«¬ ¨´ ­nªœ

fourier

Fourier Transform

„o­¤„µ¦

laplace

LaplaceTransform

dsolve

„o­¤„µ¦Á·Š°œ»¡œ³ ›r

ztrans

Z Transform

finverse

®µ inverse …°Š fnction

taylor

Taylor Series

subs

solve

®µ¨·¤·˜

plot

GRAPH DISPLAY FUNCTIONS polar „µ¦¡¨È°˜„¦µ¢Á·ŠÁ­oœ x-y ¡¨È°˜„¦µ¢Äœ¦¼žÁ·Š…³Êª

axis

„ε®œ—¨³„¬–´Â„œ

pie

­¦oµŠÂŸœ£¼¤·ªŠ„¨¤

grid

­—Š grid ®¦º°Å¤n

bar

­¦oµŠÂŸœ£¼¤·ÂšnŠ

hold

‡Š¦¼žÁ—·¤°¥¼n®¦º°Å¤n

stem

¡¨È°˜Äœ¦¼ž…ªœ°·¤Á¡µ­r

xlabel

„ε®œ—‡Îµ°›·µ¥œÂ„œ x

hist

ylabel

„ε®œ—‡Îµ°›·µ¥œÂ„œ y

scatter

¡¨È°˜‹»—„¦´‹µ¥˜³ª

„ε®œ—®³ª…o°„¦µ¢

contour

­¦oµŠÁ­oœ contour

title legend

„ε®œ—ºÉ°…°Š„¦µ¢Â˜n¨´Á­oœ

­¦oµŠ histogram

fill

¦´µ¥­¸Ä®o¦¼ž polygon

text

¡·¤¡r…o°‡ªµ¤Á¡·¤É Á˜·¤

ezplot

¡¨È°˜„¦µ¢‹µ„¢{Š„rœ³É

line

ªµ—Á­oœ˜¦ŠÁ¡·É¤Á˜·¤

figure

Ážd—®œoµ˜nµŠ¦¼ž£µ¡Ä®¤n

semilogx

Á®¤º°œ plot ˜n‡µn Ĝ„œ x Áž}œ log “µœ 10

subplot

semilogy

Á®¤º°œ plot ˜n‡µn Ĝ„œ y Áž}œ log “µœ 10

clf

loglog

Á®¤º°œ plot ˜n‡µn Áž}œ log “µœ 10 š³ŠÊ 2 „œ

close

nŠ®œoµ˜nµŠ¦¼ž£µ¡ ¨¦¼žÄœ®œoµ˜nµŠ¦¼ž£µ¡ žd—®œoµ˜nµŠ¦¼ž£µ¡

GRAPHIC HANDLING FUNCTIONS get

°nµœ handle

˜³ŠÊ ‡nµ handle

set

FILE INPUT AND OUTPUT FUNCTIONS fopen fgetl Ážd—Å¢¨r ¦³…o°¤¼¨Äœ¦¦š³—˜n°Åž fclose

fprintf

žd—Å¢¨r

Á…¸¥œ…o°¤¼¨¨ŠÄœÅ¢¨r

imread

IMAGE FUNCTIONS imagesc ¡¨È°˜¦¼žÃ—¥„µ¦šÎµ scaling …o°¤¼¨„n°œ ¦³…o°¤¼¨ž¦´Á£š¦¼ž£µ¡

imwrite

­¦oµŠÅ¢¨r¦¼ž‹µ„…o°¤¼¨

colormap

Áž¨¸É¥œÃšœ­¸

¡¨È°˜¦¼ž

colorbar

­—ŠÂ™­¸Áš¸¥‡nµ

image

AUDIO FUNCTIONS wavread

°nµœ…o°¤¼¨‹µ„Å¢¨r .wav

wavrecord

wavwrite

­¦oµŠÅ¢¨rÁ­¸¥Š‹µ„…o°¤¼¨

wavplay

°³—Á­¸¥Š‹µ„°»ž„¦–r°·œ¡»˜ ­nŠÁ­¸¥Š°°„šµŠ¨ÎµÃ¡Š

Related Documents

Matlab Basic Signal
June 2020 4
Basic Concepts In Matlab
November 2019 18
Basic Concepts In Matlab
December 2019 16
Signal
April 2020 23