CHP 1: Logical AND
CHP 1: Logical AND
Logical AND.
A & B performs a logical AND of arrays A and B and returns an array
containing elements set to either logical 1 (TRUE) or logical 0
(FALSE). An element of the output array is set to 1 if both input
arrays contain a non-zero element at that same array location.
Otherwise, that element is set to 0. A and B must have the same
dimensions unless one is a scalar.
C = AND(A,B) is called for the syntax 'A & B' when A or B is an
object.
Note that there are two logical AND operators in MATLAB. The &
operator performs an element-by-element AND between matrices, while
the && operator performs a short-circuit AND between scalar values.
These operations are explained in the MATLAB Programming documentation
on logical operators, under the topic of Basic Program Components.
Arithmetic Operation
These operations are addition, subtraction, multiplication, division, or powers between two numbers.
Arithmetic Operator
These are symbols reserved to mean arithmetic operation +,-,*,/,^.
Command Window
The window where commands are executed and responses displayed.
Command Prompt
Where you type commands in the command window. >>
Command History Window
Window that contains all previously entered commands.
Comparison Operator
Compare the values of two numbers, and used to build logical expressions.
Current Directory
Folder in your computer where files will be saved and where you will have direct access to are stored.
Current Directory Window
Window that lists all the files currently stored in the directory.
Execute
A program that is resolved by the computer.
Help Function
A command used to view description of any function in MATLAB.
Logical Expression
A statement that is true or false.
Logical Operator
Operations between two logical expressions. AND, OR, NOT, XOR
MATLAB Environment
Text based visualization tool that allows interaction with MATLAB.
Mathematical Expression
Denotes a truth statement.
Logical NOT
Logical NOT.
~A performs a logical NOT of input array A, and returns an array
containing elements set to either logical 1 (TRUE) or logical 0 (FALSE).
An element of the output array is set to 1 if A contains a zero value
element at that same array location. Otherwise, that element is set to 0.
B = NOT(A) is called for the syntax '~A' when A is an object.
Order of Operations
Arithmetic before comparison before logical. Parenthesis change order and clarify order.
Logical OR
Logical OR.
A | B performs a logical OR of arrays A and B and returns an array
containing elements set to either logical 1 (TRUE) or logical 0
(FALSE). An element of the output array is set to 1 if either input
array contains a non-zero element at that same array location.
Otherwise, that element is set to 0. A and B must have the same
dimensions unless one is a scalar.
C = OR(A,B) is called for the syntax 'A | B' when A or B is an
object.
Note that there are two logical OR operators in MATLAB. The |
operator performs an element-by-element OR between matrices, while
the || operator performs a short-circuit OR between scalar values.
These operations are explained in the MATLAB Programming documentation
on logical operators, under the topic of Basic Program Components.
Truth Table
Results of every truth combination laid out in a table.
Workspace Window
Window that lists all variables currently being used in the workspace.
Logical XOR
XOR Logical EXCLUSIVE OR.
XOR(S,T) is the logical symmetric difference of elements S and T.
The result is logical 1 (TRUE) where either S or T, but not both, is
nonzero. The result is logical 0 (FALSE) where S and T are both zero
or nonzero. S and T must have the same dimensions (or one can be a
scalar).
Functions and Operators:
+: add
~=: relational not
equal to log: LOG(X) is the natural logarithm of the elements of X.
-: subtract ==: relational equal to log10: LOG10(X) is the base 10 logarithm of the elements of X.
*: multiply &&: logical and
help: HELP('syntax') displays help describing the syntax used in
MATLAB commands and functions. HELP(TOPIC) returns the help
text for TOPIC as a string.
/: divide ||: logical or format short: Set output format 5 digits.
^:exponent ~: logical not format long: Set output format 15 digits.
(): parenthesis and
subscripting
ans: most recent
answer format bank: Set output format dollars and cents.
>: relational greater than pi: 3.1415926535897 NaN: Not-a-Number.
>=: relational greateer
than or equal to
sin: SIN(X) is the sine
of the elements of X. Inf: Infinity.
<: relational less than
cos: COS(X) is the
cosine of the
elements of X. i: Imaginary unit.
<=: relational less than or
equal to
exp: EXP(X) is the
exponential of the
elements of X, e to
the X.
Chp 2:
Array
A rectangular table of values, not necessarily numerical.
Array Indexing
Obtain element in a row and column. A(r,c)
Assign
Takes a known value and puts it in a variable.
Assignment Operator
Operator used to assign values to variables. =
Cell
CELL Create cell array.
CELL(N) is an N-by-N cell array of empty matrices.
CELL(M,N) or CELL([M,N]) is an M-by-N cell array of empty
matrices.
CELL(M,N,P,...) or CELL([M N P ...]) is an M-by-N-by-P-by-...
cell array of empty matrices.
CELL(SIZE(A)) is a cell array the same size as A containing
all empty matrices.
Char
CHAR Create character array (string).
S = CHAR(X) converts the array X that contains nonnegative integers
representing character codes into a MATLAB character array (the first
127 codes are ASCII). The actual characters displayed depends on the
character encoding scheme for a given font. The result for any
elements of X outside the range from 0 to 65535 is not defined (and
may vary from platform to platform). Use DOUBLE to convert a
character array into its numeric codes.
S = CHAR(C), when C is a cell array of strings, places each
element of C into the rows of the character array S. Use CELLSTR to
convert back.
S = CHAR(T1,T2,T3,..) forms the character array S containing the text
strings T1,T2,T3,... as rows. Automatically pads each string with
blanks in order to form a valid matrix. Each text parameter, Ti,
can itself be a character array. This allows the creation of
arbitrarily large character arrays. Empty strings are significant.
Concatenate
Use brackets to create an array. [] Columns are separated by , and rows by ;.
Concatenation
Verb form of concatenate.
Data Type
A classification of the type of information that is stored in a variable.
Double
DOUBLE Convert to double precision.
DOUBLE(X) returns the double precision value for X.
If X is already a double precision array, DOUBLE has
no effect.
DOUBLE is called for the expressions in FOR, IF, and WHILE loops
if the expression isn't already double precision. DOUBLE should
be overloaded for all objects where it makes sense to convert it
into a double precision value.
Element of a Matrix
A unit of information contained in a matrix.
Element by Element Matrix Manipulation
Take every element and multiply it by corresponding element in another matrix. .* (dot times)
Field
The parts of a struct that define the properties of each element.
Index of a Matrix
An address within a matrix or array.
Matrix
A rectangular table of values, not necessarily numerical.
Sprintf Type Input
A function can take in formatted strings in the same way as sprint.
String
An array of chars, usually one dimensional.
Struct
STRUCT Create or convert to structure array.
S = STRUCT('field1',VALUES1,'field2',VALUES2,...) creates a
structure array with the specified fields and values. The value
arrays VALUES1, VALUES2, etc. must be cell arrays of the same
size, scalar cells or single values. Corresponding elements of the
value arrays are placed into corresponding structure array elements.
The size of the resulting structure is the same size as the value
cell arrays or 1-by-1 if none of the values is a cell.
STRUCT(OBJ) converts the object OBJ into its equivalent
structure. The class information is lost.
STRUCT([]) creates an empty structure.
To create fields that contain cell arrays, place the cell arrays
within a VALUE cell array. For instance,
s = struct('strings',{{'hello','yes'}},'lengths',[5 3])
creates the 1-by-1 structure
s =
strings: {'hello' 'yes'}
lengths: [5 3]
Example s = struct('type',{'big','little'},'color','red','x',{3 4})
Transpose
Switch rows and columns in a matrix.
Unassigned Command
Result of an operation that is not assigned to a variable.
Variable
A string of characters and numbers associated with a piece of information.
Vectorized
A function that takes an array as input and performs a function on it.
Workspace
The space in a computers memory being utilized to store variables.
Functions and Operators:
.: Structure field access
fliplr: FLIPLR(X) returns X with row
preserved and columns flipped in the
left/right direction.
rand: R = RAND(N) returns an N-
by-N matrix containing pseudo-
random values
:: pick out selected rows, columns and
elements of vectors, matrices, and
arrays.
getfield: F = S.field returns the contents of
the specified field.
randn: R = RANDN(N) returns an
N-by-N matrix containing pseudo-
random values
;: The semicolon is used inside
brackets to indicate the ends of the
rows of a matrix. It is also used after
an expression or statement to
suppress printing. i: Imaginary unit.
rmfield: S = RMFIELD(S,'field')
removes the specified field from
the m x n structure array S.
=: Assignment. Inf: Infinity.
setfield: S.field = V sets the
contents of the specified field to V
[]: Brackets are used in forming
vectors and matrices.
isfield: ISFIELD(S,FIELD) returns true if the
string FIELD is the name of a field in the
structure array S.
size: [M,N] = SIZE(X) for matrix X,
returns the number of rows and
columns in X as separate output
variables.
{}: Braces are used to form cell arrays.
length: LENGTH(X) returns the length of
vector X.
sprintf: Write formatted data to
string. sprintf('The array is
%dx%d.',2,3) The array is 2x3.
sprintf('\n') is the line termination
character on all platforms.
cell: CELL(N) is an N-by-N cell array of
empty matrices.
linespace: LINSPACE(X1, X2) generates a
row vector of 100 linearly equally spaced
points between X1 and X2.
strcmp: TF = STRCMP(S1,S2)
compares the strings S1 and S2
and returns logical 1 (true) if they
are identical, and returns logical 0
(false) otherwise.
clc: Clear command window.
lower: B = LOWER(A) converts any
uppercase to lowercase
strcmpi: TF = STRCMPI(S1,S2)
compares the strings S1 and S2
and returns logical 1 (true) if they
are the same except for case, and
returns logical 0 (false) otherwise.
clear: removes all variables from the
workspace. NaN: Not-a-Number.
upper: B = UPPER(A) converts any
lower case characters to upper
case
clear all: removes all variables,
globals, functions and MEX links.
num2str: NUM2STR(X) converts the matrix
X into a string representation T with about 4
digits and an exponent if required. This is
useful for labeling plots with the
TITLE,XLABEL, YLABEL, and TEXT commands.
whos: lists all the variables in the
current workspace, together with
information about their size,
bytes, class, etc.
fieldnames: NAMES =
FIELDNAMES(S) returns a cell array of
strings containing
the structure field names
associated with the structure s.
ones: ONES(M,N) or ONES([M,N]) is an M-
by-N matrix of ones.
zeros: ZEROS(M,N) or
ZEROS([M,N]) is an M-by-N matrix
of zeros.
Chp3:
Anonymous Function
A function handle that is assigned to a function not stored. F = @(inputs) function definition
Body of the Function
Sequence of instructions that compute the results of the function.
Cell
A piece of script code that can be run individually.
Comment
A line within the function that is not read as code but is a descriptive device to aid in navigating the function.
Editor
Text environment that allows you to build, edit, and save functions.
Function
A sequence of instructions that performs a specific task.
Function Handle
Variables that have been assigned to functions as their value. @
Function Header
The way a functions type definition is given to MATLAB.
Function Workspace
Space in the computer memory reserved for variables within a function.
Input Arguments
User defied input.
Keyword
Reserved words that carry a specific meaning.
Local Variable
Variable defined in the function workspace.
M-File
Standard file type for MATLAB functions.
Output Arguments
Results of the function the user expects to receive.
Overload
Naming a function with the same name as another and putting it higher in the MATLAB path.
Parent Function
A function that holds a subfunction. The subfunction is declared after the end statement of the parent.
Path
The order in which MATLAB searches for a function.
Run
The execution of a function.
Script File
M-file that contains a sequence of instructions but is not a function. It shares workspace with the current directory.
Subfunction
A function defined in the same m-file as a parent function. Only the parent function can call it.
Type Definition
A list of input and output arguments by data type.
User
Entity calling the function.
Functions and Operators:
ceil: CEIL(X) rounds the
elements of X to the
nearest integers towards
infinity.
function: Add new
function. function
[mean,stdev] = stat(x)
%: Comment your
code.
end: Terminate scope of
FOR, WHILE, SWITCH, TRY,
IF statements and m files.
return: RETURN causes
a return to the invoking
function or to the
keyboard. It also
terminates the
KEYBOARD mode.
%%: Create code
cells, evaluate with
evaluate cell button.
find: FIND indices of
nonzero elements. I =
FIND(X) returns the linear
indices corresponding to
the nonzero entries of the
array X. X may be a logical
expression.
round: ROUND(X)
rounds the elements of
X to the nearest
integers.
@: The at symbol is
used to create a
function_handle.
floor: FLOOR(X) rounds the
elements of X to the
nearest integers towards
minus infinity.
sum: S = SUM(X(:)) is
the sum of the
elements of the matrix
X.
Chp4:
Branching Statement
Code construct that executes blocks of code only if certain conditions are met.
Conditional Statement
Logical expressions after the if and elseif statements.
If-Else Statement
A condition that covers any other case.
If-Statement
Determines if the associated logical expression is true.
Nested
A statement that is entirely contained within another statement of the same type as itself.
Nested If-Statement
An if-statement that is entirely contained within a clause of another if-statement.
Functions and Operators:
all: True if all elements of a
vector are nonzero. ALL(X)
operates on the columns of X,
returning a row vector of logical
1's and 0's
Elseif: ELSEIF is used with IF. The
statements after the ELSEIF are executed if
the expression is true and all the preceding
IF and ELSEIF expressions are false. Does
not need an end statement
isinf: True for infinite
elements. ISINF(X) returns an
array that contains 1's where
the elements of X are +Inf or
-Inf and 0's where they are
not.
any: True if any element of a
vector is a nonzero number or is
logical 1 (TRUE). Ignores Nan.
ANY(X) operates on the columns
of X, returning a row vector of
logical 1's and 0's.
error: ERROR('MSGID', 'MESSAGE')
displays the error message in the string
MESSAGE, and causes an error exit from
the currently executing M-file to the
keyboard. MSGID is a message identifier,
that you can use to uniquely identify the
error.
isnan: True for Not-a-
Number. ISNAN(X) returns an
array that contains 1's where
the elements of X are NaN's
and 0's where they are not.
ctrl+i: Indents everything
properly, use with ctrl+a which
selects everything
if: Conditionally execute statements.
If expression
statements
end
isreal: True for real array.
ISREAL(X) returns 1 if X does
not have an imaginary part
and 0 otherwise.
else: ELSE is used with IF. The
statements after the ELSE are
executed if all the preceding IF
and ELSEIF expressions are false.
isa: True if object is a given class.
ISA(OBJ,'classname') returns true if OBJ is
an instance of 'classname'.
strcmp: Compare strings. TF
= STRCMP(S1,S2) compares
the strings S1 and S2 and
returns logical 1 (true) if they
are identical, and returns
logical 0 (false) otherwise.