Final Review Flashcards
Functions
special M-files that have their own workspace, do not have access to the variables in the Command window workspace and cannot change those variables. Receive data through input argument list, return results through output argument list function [list of output arguments] = function_name[list of input arguments]
dummy arguments
the input and output arguments specified in a function
actual arguments
when a function is called/invoked in a script or in another function
local variables
available only in the function where they are defined
global variables
shared between all workspaces using “global memory” , any function can change the values of a global variable.
nargin(‘function_name’)
returns number of input arguments of a function
-1 if various numbers of arguments are allowed
nargout(‘function_name’)
returns number of output arguments of a function
-1 if various numbers of arguments are allowed
fminbnd
minimizes a function of one variable
fzero
finds a zero of a function of one variable
quad
numerically integrates a function
fplot
plots a function in given limits on x- and y- axis
ezplot
“easy” function plotter using default limits
strings
1-D arrays of chars, also created by single quotation marks: ‘string’
character constants
have type char and are created by enclosing characters in single quotation marks ‘a’
ischar(variable)
tests for presence of a scalar char or an array of chars, returns 1 if true and 0 if not
char()
converts type to character
if an array, automatically pads entries with whitespaces to make same number of columns
double()
converts type to double; double value of a character is the numerical code used in MATLAB to represent that character
character arrays
arrays with character entries
each row of a 2-D character array must have the same number of columns or it will produce a MATLAB error
can pad with whitespaces to make it fit
deblank()
emoves all of the whitespace characters from the end of a string
NOTE: whitespace characters correspond to ASCII codes for spaces: SP , horizontal tabs: (HT), linefeeds (LF), vertical tabs (VT) form feed (FF) and carriage return (CR)
strtrim()
removes all leading AND trailing whitespace characters from a string
strcat()
concatenates/joins two or more strings and deletes any trailing whitespace
ex: strcat( ‘string1 ‘, ‘string2 ‘) = string1string2
strvcat()
joins two or more strings together vertically and automatically adds padding
relational operators for char
when relational operators are used for characters, they compare the values of the corresponding ASCII codes
can also be used to compare strings, but strings MUST HAVE EQUAL DIMENSIONS. returns a one in any position where the strings have the same character and a zero in positions where the strings differ
strcmp()
determines whether or not two strings are 1. equal in length and 2. contain the same characters
strcmpi()
determines whether or not two strings are 1. equal in length and 2. contain the same characters but ignores upper vs lowercase
strncmp()
determines whether two strings contain the same n leading characters
strncmpi()
determines whether two strings contain the same n leading characters, ignores upper vs lowercase
findstr(‘string’, ‘substring’)
finds the starting position of ALL occurrences of a substring within an identified string
strmatch()
finds the rows in an array that match the given substring, returns them like:
result = strmatch(‘substring’, string_variable)
result =
1
2
strrep(string_variable, ’substring_to_be_replaced’,’new_substring’)
finds and replaces all occurrences of the first listed substring with the second one
upper()
modifies a string by converting all lower case letters to upper case
lower()
modifies a string by converting all upper case letters to lower case