Escolar Documentos
Profissional Documentos
Cultura Documentos
Definitions (cont)
if Selection Structure
if comparison
[commands to do
something]
end
values: 0 or 1
of its existence.
condition is met).
Relational Operators
< less than
<= Less than or equal to
> greater than
>= greater than or equal to
== equality check
~= not equal to
A_augmented = [A b]
RREF_result =
rref(A_augmented);
exponent
solution =
RREF_result(:,end)
A4= (A)(A)(A)(A)
operations.
Sentinel Loop- A loop that
terminates only when a specific
met
Find Command
The command find searches a
xor exclusive or
Code Vectorization- A
Solving Matricies
solution = inv(A)*b
scalars)
Matrix Functions
valid results.
element-by-element operation
code
(identity matrix)
output processes
point
index = find(x)
elements)
index = find(x,k,'last')
(last k elements)
be wrong.
Rectangle/Square - Indicates
calculations
if/else/elseif
if comparison % do
something
elseif comparison % do
something else
Definitions
end
Sponsored by Readability-Score.com
cheatography.com/xsgirl99/
Page 1 of 4.
https://readability-score.com
Menus
box.
Syntax: var =
menu('title','option
1','option 2','...')
Use in conjunction with Switches.
x=menu('S','x','y'...) if
if/elseif/else.
Often personal preference, though
you will often see switches when
checking strings.
Important: In MATLAB, once a
true case has been found
MATLAB will NOT check the other
cases make sure you plan
accordingly.
clock times)
Alternatives: Array operations,
find command, Code
vectorization
1. for loop - Primarily used if you
know a priori( Before the fact) how
array constructors)
...), reshape(A,r,[])
horzcatcommand
disp('I''m at the
size
loop.
A = 'We are!'
B = [1 4; 3 2]
C = 'Penn State!'
D = single([1 2; 3 4])
E = {A,B,C,D} % default printing
just shows sizes
display
For Loop
for some_index_variable =
concatenates horizontally
diagonal
Output:
numel vs find
end
switch location
disp('I''m lost')
array is an array.
otherwise
S==2->fprintfy
lion shrine')
Cell Arrays
Switch Example
Loops
S==1->fprintfx elseif
main diagonal
letter or symbol.
Character Arrays
some_matrix
some commands to be
executed
end
Sponsored by Readability-Score.com
cheatography.com/xsgirl99/
Page 2 of 4.
https://readability-score.com
Transpose Command
Input: for k = [1 3 5 7]
becomes A(j,i)
components.
restriction.
Dingle<complex # of
singles=double
k
end
Command (2 versions):
transpose(x) or x'
Dot Product
A*B=[(a 11b 11
techniques.
Timing Functions
L.nums = [1 4; 3 2]
L.myphrase2 = 'Penn State!'`
Cross Product
timing
(cont)
Structure Arrays
+a 22b 22)
clock/etime performs
MATLAB loops.
Double-Precision Floating-Point
Sponsored by Readability-Score.com
cheatography.com/xsgirl99/
Page 3 of 4.
https://readability-score.com
num_rows = 3;
num_cols = 4;
if grades(count) >= 90
num_pages = 2;
A_loop = A_loop + 1;
value = 46;
A = zeros(num_rows,
80
num_cols, num_pages); %
B_loop = B_loop + 1;
Optional
for k = 1:num_pages %
for i = 1:num_rows %
loop over # of rows
for j = 1:num_cols %
loop over # of cols
70
C_loop = C_loop + 1;
else
failing_loop =
failing_loop + 1;
end
A(i,j,k) = value;
end
value = value - 2;
fprintf('%i A''s\n',
end % cols
A_find)
end % rows
fprintf('%i B''s\n',
end % pages
B_find)
disp(A)
fprintf('%i C''s\n',
C_find)
matrix A.
grades = load('P50.csv');
A_find =
if rem(k,2)==0 Checks to
see if k is divisible by 2(even)
B_find =
numel(find(grades >= 80 &
grades < 90));
logspace(start,end,interva
failing_find)
numel(find(grades>=90));
Exam 1 Material
fprintf('%i D''s\n',
C_find =
By xsgirl99
Sponsored by Readability-Score.com
cheatography.com/xsgirl99/
Page 4 of 4.
https://readability-score.com