2. Script files 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.Â
3. Script files 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.Â
14. String Handling Creating strings 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. >> first = 'John'; >> last = 'Coltrane'; >> name = [first,' ',last]
15. String Handling >> string='This is a stringâ >> string(3) % gives the third element in the variable words. ans = i >> string(2)='t' % replaces the second element in the vector with t.
16. String Handling >> Y= input('Please type something here: ','s'); % Matlab expects a number, string or a matrix from the keyboard. % The second argument says the returned variable should be a string. >> disp('The name is: '), disp(x) % gives text as output and the value of x.
17. String Handling Also, different formats can be converted to âstringsâ and vice verse. Here are some examples of functions that help in converting between different formats: int2str(n)Â Converts an integer n to a string hex2num(hstr)Â Converts hexadecimal number hstr to a float. hex2dec(hstr) Â Converts hexadecimal string to decimal integer. 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.
18. String Handling There are several functions available to manipulate or fetch appropriate data from strings: blanks(n)Â Gives a string with n blanks deblank(str)Â Subtracts all blanks at the end of the string. lower(str)Â All letters are changed to small. upper(str)Â All letters are changed to capital. ischar(str)Â If string contains character => gives 1 in return, 0 otherwise.
19. String Handling There are several functions available to manipulate or fetch appropriate data from strings: isletter(str(i))Â If element number i in the string is a letter=> gives one in return. isspace(str)Â True for white space characters. strcmp(str1,str2)Â returns 1 if strings S1 and S2 are the same and 0 otherwise. strcmpi(str1,str2)Â returns 1 if strings S1 and S2 are the same except forcase and 0 otherwise.
20. String Handling There are several functions available to manipulate or fetch appropriate data from strings: strfind(str1,str2)Â returns the starting indices of any occurrences of the string str2 in the string str1. findstr(str1,str2)Â returns the starting indices of any occurrences of the shorter of the two strings in the longer.
21. Visit more self help tutorials Pick a tutorial of your choice and browse through it at your own pace. The tutorials section is free, self-guiding and will not involve any additional support. Visit us at www.dataminingtools.net