MATLAB Practice 2 Introducing MATLAB Lecture Notes on
MATLAB Practice 2 Introducing MATLAB Lecture Notes on Video Search & Mining, Spring 2012 Presented by Jun Hee Yoo Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http: //bi. snu. ac. kr
MATLAB Practice 2 – MATLAB Introduce Function © 2012, SNU CSE Biointelligence Lab. , http: //bi. snu. ac. kr 2
Function n MATLAB functions n n Multiple input arguments Multiple returns function [output 1, output 2] = foo(input 1, input 2, input 3) Statements end n n void input arguments void returns function foo Statements end © 2012, SNU CSE Biointelligence Lab. , http: //bi. snu. ac. kr 3
Function n In function statement n You can use ‘return’ keyword but it’s not mandatory function [output 1, output 2] = foo(input 1, input 2, input 3) Statements return; end n You must declare variable or matrix that has same name as outputs before return or end of function [output 1, output 2] = foo(input 1, input 2, input 3) …. output 1 = 1; output 2 = 2; …. return; end © 2012, SNU CSE Biointelligence Lab. , http: //bi. snu. ac. kr 4
Function n Create function_name. m in your MATLAB Menu © 2012, SNU CSE Biointelligence Lab. , http: //bi. snu. ac. kr Right Click on Browser Or, just CTRL+N to call empty document. 5
Function n Create function_name. m in your MATLAB filename must be same as function name. (in our case, this file must be saved name as foo. m) © 2012, SNU CSE Biointelligence Lab. , http: //bi. snu. ac. kr
Functions n One function_name. m must have one primal function which name is same as file name. n One function_name. m can has multiple subfunctions which located under primal functions. © 2012, SNU CSE Biointelligence Lab. , http: //bi. snu. ac. kr 7
Functions © 2012, SNU CSE Biointelligence Lab. , http: //bi. snu. ac. kr 8
Functions n Scope of variables n Scope of MATLAB is like C/C++ or JAVA n Generally, every internal function variables – exclude return values - in function are removed when function is returned. n But, with persistent keyword, internal function variables will remain after function returned. © 2012, SNU CSE Biointelligence Lab. , http: //bi. snu. ac. kr 9
Useful Tips n help function_name | command_name n n show the description of function or command. lookfor keywords n This command takes some time. © 2012, SNU CSE Biointelligence Lab. , http: //bi. snu. ac. kr 10
- Slides: 10