lecture 1

Post on 05-Jan-2016

22 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Lecture 1. Current directory & Path Setting Programs Scripts Functions. Function myadd. myadd.txt Experiment Download myadd.m and store it to some directory ( named ‘code’) Set current directory to where myadd.m is stored. >> myadd(2,3,4) ans = 9. >> myadd(2,3) ans = 5. - PowerPoint PPT Presentation

TRANSCRIPT

11軟體實作與計算實驗軟體實作與計算實驗

Current directory & Path Setting

Programs• Scripts• Functions

Lecture 1Lecture 1

22軟體實作與計算實驗軟體實作與計算實驗

Function myaddFunction myadd

myadd.txt

ExperimentExperiment Download myadd.m and store it to some Download myadd.m and store it to some

directory ( named ‘code’)directory ( named ‘code’) Set current directory to where myadd.m is Set current directory to where myadd.m is

storedstored>> myadd(2,3)

ans =

5

>> myadd(2,3,4)

ans =

9

33軟體實作與計算實驗軟體實作與計算實驗

Set current directory to where Set current directory to where myadd.m is storedmyadd.m is stored

44軟體實作與計算實驗軟體實作與計算實驗

Function circle_areaFunction circle_area

circle_area.m

Experiment (1)Experiment (1) Download circle_area.m and store it in some Download circle_area.m and store it in some

directory ( named ‘area’ )directory ( named ‘area’ ) Set current directory to where circle_area is Set current directory to where circle_area is

storedstored>> circle_area(2)

ans =

12.5664

>> circle_area(3)

ans =

28.2743

55軟體實作與計算實驗軟體實作與計算實驗

Set current directory to where Set current directory to where circle_area.m is storedcircle_area.m is stored

66軟體實作與計算實驗軟體實作與計算實驗

Undefined functionsUndefined functions

Experiment (2)Experiment (2) Set current directory to ‘code’Set current directory to ‘code’

Unable to reach directory ‘area’Unable to reach directory ‘area’

MATLAB engine found no function that is MATLAB engine found no function that is named as ‘circle_area’named as ‘circle_area’

>> myadd(circle_area(2),circle_area(3))??? Undefined command/function 'circle_area'.

77軟體實作與計算實驗軟體實作與計算實驗

Add folds to pathAdd folds to path

Access user-created MATLAB functionsAccess user-created MATLAB functions

Add directory ‘area’ to pathAdd directory ‘area’ to path Click ‘file’Click ‘file’ Select ‘set path’ Select ‘set path’ Press ‘add fold’Press ‘add fold’ Select directory that stores ‘circle_area.m’ Select directory that stores ‘circle_area.m’

88軟體實作與計算實驗軟體實作與計算實驗

Add FolderAdd Folder

99軟體實作與計算實驗軟體實作與計算實驗

Experiment (3)Experiment (3)

Set current directory to ‘code’Set current directory to ‘code’Add ‘area’ to pathAdd ‘area’ to pathExecute Execute

Now both ‘myadd’ and ‘circle_area’ are Now both ‘myadd’ and ‘circle_area’ are well defined and reachable well defined and reachable

>> myadd(circle_area(2),circle_area(3))

ans =

40.8407

1010軟體實作與計算實驗軟體實作與計算實驗

Matlab functionsMatlab functions

Built-in functionsBuilt-in functions

User-created functionsUser-created functions

1111軟體實作與計算實驗軟體實作與計算實驗

Built-in functionsBuilt-in functions

ExamplesExamples Matrix generation : rand, zeros, ones, eyeMatrix generation : rand, zeros, ones, eye Matrix manipulation : eig, size, repmat, Matrix manipulation : eig, size, repmat,

reshapereshape Algebraic functions : sin, cos, tan, tanh, exp, Algebraic functions : sin, cos, tan, tanh, exp,

log…log…

I/OI/O load, plot, input, display, imread, imageload, plot, input, display, imread, image

1212軟體實作與計算實驗軟體實作與計算實驗

Matrix generationMatrix generationrand rand generate a matrix whose elements are sampled from generate a matrix whose elements are sampled from

random variablesrandom variables

zeros zeros generate a matrix whose elements are all zerosgenerate a matrix whose elements are all zeros

ones ones generate a matrix whose elements are all onesgenerate a matrix whose elements are all ones

eye eye generate an identity matrix generate an identity matrix

1313軟體實作與計算實驗軟體實作與計算實驗

randrand

rand(m,n)rand(m,n) Create an mxn matrix with elements sampled Create an mxn matrix with elements sampled

from a uniform distributionfrom a uniform distribution

1414軟體實作與計算實驗軟體實作與計算實驗

zeroszeros

zeros(m,n)zeros(m,n) Create an mxn matrix with zero elementsCreate an mxn matrix with zero elements

1515軟體實作與計算實驗軟體實作與計算實驗

onesones

ones(m,n)ones(m,n) Create an mxn matrix with all elements Create an mxn matrix with all elements

equaling onesequaling ones

1616軟體實作與計算實驗軟體實作與計算實驗

eyeeye

eye(m)eye(m) Create an mxm identity matrixCreate an mxm identity matrix

1717軟體實作與計算實驗軟體實作與計算實驗

User-defined functionsUser-defined functions

User-defined functionsUser-defined functions New a fileNew a file Define a function and store it to some directory with some function Define a function and store it to some directory with some function

namename

MATLAB toolboxesMATLAB toolboxes Functions created by third partiesFunctions created by third parties

Signal processSignal processStatisticsStatisticsBioinformaticsBioinformaticsNeural networksNeural networksImage processImage process

1818軟體實作與計算實驗軟體實作與計算實驗

Access of Matlab functionsAccess of Matlab functions

Function calls drive Matlab engine to Function calls drive Matlab engine to search functions search functions

Searching directoriesSearching directories Current directoryCurrent directory Then directories added in pathThen directories added in path

Top downTop down

top related