ENG 006 Lecture Notes
ENG 006 Lecture Notes
ANS: D
Logical Operators:
EX:
Girl = 1 (true)
Boy = 0 (false)
class(Girl) = logical
EX:
Apple = true; pear =~apple
Output: Pear = false
EX:
Girl = 1, boy=~girl
class(Girl) = ‘double’
class(boy) = ‘logical
- or(A,B) // A|B
4/11
Exclusive or operator: checking for a difference in the 2 inputs
- xor(A,B)
False XOR false = false
True XOR false = true
iclicker question:
(x|~x)&0
Output = false
“ && ” it wont perform the second operation
Ex: x=1; (x>5) && (x>10)
“ || “ it won’t perform the other operation, just “|” it will go through both
Scripts:
Functions:
function[finBalance, interest] = BalanceWithInterestBoth(rate, intBalance)
4/13
2D array= [rowArray1;rowArray2;Array3]
INDEXING:
Linear Indexing = 1 integer row array =
myArray(index#)
1 4
2 5
3 6
EXAMPLE:
Row = [3,4,5,6,7,8]
indexArray = [1,3,5]
Row(indexArray) => [3, 5, 7]
Sub = A([2,3],[2,4])
Row 2,column 2 // row 3, col4
04/18/23
A = [1,2,3;4,5,6;7,8,9]
A(:,2) % all the rows, second column
A(2,:) = -1 %second row, all the elements -1
A(:,:) = -1 % all columns and all rows // can also do this
A(:) % flattens the array : if the proportions are the same, then it won’t flatten (Video)
A(2,end) % 2nd row last element
A(end-1:end,1:2) the left lower corner 4
rowA = [1:3]
rowA(end) = 3
04/20/23
Mod(23,5) —> remainder 3
Mod(23,-5) —> remainder -2
Rem(23,5) —> 3
X=[1:12]
Mod(x) —> 012012012
Plotting:
Plot(arrayx,arrayy)
Title(“..”)
Xlabel(“..” and ylabel(“..”)
Grid on
Ginput(#) %% captures # points; without #, as many as u want
R
4/25
Min and Max
[val1,val2] = min(Array)
Val1 = minimum
Val2 = index
2D array
[minimum,index] = min(array)
Goes through each column and returns the indices separately
957
340
429
Min(array) → 3 , 2, 0 // indices = 2, 3, 2
Sum will add down of the columns if 2D array
sum([1,2]) = 3
sum(x,1) // 1= column ; 2 = rows
- sum(mat2D(:)) %% flattens the array, and then sums all the elements
Prod, mean, mode
Sort
[sortedRow,sortedIndex] = ]sort(2D array)
sortedIndex : index for each column
sortedIndex = 2,3,2
3,2,1
1,1,3
957
340
429
Fliplr = flips left right
Flipud = flip up and down etc.
Sortrow
Doesn’t sort rows,
sortrow(array,#)
Will sort the # column, and the rest of them will be the corresponding row.
Union joins the 2 arrays and removes the repeating
04/27/2023
Lower(..) = all lower case
Upper(…) - all upper case
05/02/2023
Adding 2D arrays through for loops
Animation
Break
Even if it’s a nested function, the “break” will break out of the nested function AND the while loop
will end
Continue
Will stop the current loop, but will continue for the next iteration
05/09
This one is an empty array, but if the the second line said ‘a’ instead of “a”, then it would
produce a logical index
char(‘Mercury’, ‘Gemini’)
‘Mercury’
‘Gemini ‘ %% automatically adds a space to make the rectangular array the same size
05/11
Struct(fieldname, data)
Function.fieldname = data
Extractedfield = structureName.(stringarray(index))
Orderfields = alphabetical order
When removing or updating the value, u have to reassign
Ex:
Student = Rmfield(student, data)
05/16
Object and classes
The classdef photoFrame name must match the function obj= photoFrame()
05/18
Imagesc() or imshow() to display image
- imshow needs infor from 3 layers