Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

- Excel Datamining Addin Intermediate by DataminingTools Inc 7779 views
- Data Applied:Decision Trees by DataminingTools Inc 424 views
- Apresentação Red Advisers by mezkita 780 views
- SPSS: Data Editor by DataminingTools Inc 5019 views
- XL-Miner: Timeseries by DataminingTools Inc 1148 views
- Data Applied: Developer Quicklook by DataminingTools Inc 274 views

2,642 views

Published on

Procedures And Functions in Matlab

Published in:
Technology

No Downloads

Total views

2,642

On SlideShare

0

From Embeds

0

Number of Embeds

12

Shares

0

Downloads

0

Comments

0

Likes

3

No embeds

No notes for slide

- 1. Matlab: Procedures and Functions<br />
- 2. Script files<br />Script files, also called M- files as they have extension .m, make MATLAB programming much more efficient than entering individual commands at the command prompt. A script file consists of MATLAB commands that together perform a specific task. The M-file is a text file which can be created and edited by any plain text editor like Notepad, emacs or the built-in MATLAB editor. <br />
- 3. Script files<br />Script files, also called M- files as they have extension .m, make MATLAB programming much more efficient than entering individual commands at the command prompt. A script file consists of MATLAB commands that together perform a specific task. The M-file is a text file which can be created and edited by any plain text editor like Notepad, emacs or the built-in MATLAB editor. <br />
- 4. Script files<br />Here’s an example of what a script file looks like:<br />
- 5. Script files<br />Important commands:<br />for- To print "Hello World" 10 times write<br /><ul><li>for n=1:10
- 6. disp('Hello World')
- 7. end</li></li></ul><li>Script files<br />Important commands:<br />if, else and else if-<br /><ul><li>if a == b
- 8. a = b + 1
- 9. elseif a > b
- 10. a = b - 1
- 11. else a = b
- 12. end</li></li></ul><li> User Defined Functions<br />When you use “sin” or “log” or “exp” in Matlab you are using “function m-files”. They are different from “script m-files” primarily because they have inputs and outputs. To specify which variables in the m-file are the inputs, and which are the outputs, the first line of the m-file should be in this form:<br /> function output=function_name(input)<br />
- 13. User Defined Functions<br />An example of a function:<br />
- 14. String Handling<br />Creating strings<br />Strings are matrices with character elements. The simplest way to create a string is to use it on the left side of an equal sign where the right side of the equal sign is an expression that evaluates to a string. String constants (literals) are enclosed in single quotes. The following example shows how to create string variables.<br />>> first = 'John';<br /> >> last = 'Coltrane'; <br />>> name = [first,' ',last] <br />
- 15. String Handling<br />>> string='This is a string‘<br />>> string(3) % gives the third element in the variable words. <br />ans = i<br />>> string(2)='t' % replaces the second element in the vector with t.<br />
- 16. String Handling<br />>> Y= input('Please type something here: ','s'); <br />% Matlab expects a number, string or a matrix from the keyboard. <br />% The second argument says the returned variable should be a string.<br />>> disp('The name is: '), disp(x) <br />% gives text as output and the value of x.<br />
- 17. String Handling<br />Also, different formats can be converted to ‘strings’ and vice verse. Here are some examples of functions that help in converting between different formats:<br />int2str(n) Converts an integer n to a string<br />hex2num(hstr) Converts hexadecimal number hstr to a float.<br />hex2dec(hstr) Converts hexadecimal string to decimal integer.<br />dec2hex(n) Converts decimal integer to hexadecimal string. bin2dec(str) Converts binary string to decimal integer. mat2str(A,n) Convert a 2-D matrix to a string in MATLAB syntax.<br />
- 18. String Handling<br />There are several functions available to manipulate or fetch appropriate data from strings:<br />blanks(n) Gives a string with n blanks<br />deblank(str) Subtracts all blanks at the end of the string.<br />lower(str) All letters are changed to small.<br />upper(str) All letters are changed to capital.<br />ischar(str) If string contains character => gives 1 in return, 0 otherwise.<br />
- 19. String Handling<br />There are several functions available to manipulate or fetch appropriate data from strings:<br />isletter(str(i)) If element number i in the string is a letter=> gives one in return.<br />isspace(str) True for white space characters.<br />strcmp(str1,str2) returns 1 if strings S1 and S2 are the same and 0 otherwise.<br />strcmpi(str1,str2) returns 1 if strings S1 and S2 are the same except forcase and 0 otherwise.<br />
- 20. String Handling<br />There are several functions available to manipulate or fetch appropriate data from strings:<br />strfind(str1,str2) returns the starting indices of any occurrences of the string str2 in the string str1.<br />findstr(str1,str2) returns the starting indices of any occurrences of the shorter of the two strings in the longer.<br />
- 21. Visit more self help tutorials<br />Pick a tutorial of your choice and browse through it at your own pace.<br />The tutorials section is free, self-guiding and will not involve any additional support.<br />Visit us at www.dataminingtools.net<br />

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment