matlab week 2.1 Flashcards
what should you do to matrices to properly store data?
transpose
: operator in indexing (i.e (2, :))
serves as ‘select all’ and allows you to select specific rows or columns
to a computer everything is ____
numbers.
ASCII
system that stores letters and special characters as number for computer
uint(‘a’)
returns ASCII number, in this case 97
char( 97 )
returns character that ASCII number represents, in this case a
num2str()
converts numbers to string with ASCII represented characters
str2num()
converts string to ASCII number representation
adding a number to a string…
just concatenates with ASCII rep of number, doesn’t do what you want
dimensions of array being concatenated must be…
the same
multidimensional matrix
third layer that allows multiple ‘pages’ in a book of code
find(x)
if you have an array x
locates all nonzero elements of array x and outputes the corresponding indices in x
find (X, k, ‘first’)
returns the first k indices corresponding to nonzero elements of the array
-> you can do the same with ‘last’ and it will return first k indices from the back
[row, column] = find(B)
finds indies of multidimensional matrix B that are nonzero and stores corresponding row numbers in variable row and column number in variable column
you can add optional ‘v’ to the outputs and that will return what the nonzero numbers are
what if X is a logical expression?
[row, col, v] = find( A == 9)
vector v is then logical and will contain the nonzero elements of logical array obtained by evaluating X
min function
returns smallest element in vectors, and smallest of each COLUMN in matrices
[M, I] = min(A)
returns indices corresponding to a minimum
M is min of each column
I is their indices (row number)
M = min(X, [], DIM)
finds minimum along dimension dim
1 means from each column
2 means from each row
max function
similar format as min function but finds the largest values of a matrix
mean function
takes average value of elements for vector, for matrices it takes the average for each column and returns row vector
sum function
takes the sum of all elements for vectors and returns vector with sum for each column for matrices
sort function
reorganizes data, default is smallest to largest but to reverse add ‘descend’
sortrows function
sorts rows based on specified column
ex:
sortrows(X, 1)
sorts rows of matrix X based on first column
input(‘prompt’) vs input(‘prompt’, ‘s’)
adding ‘s’ takes user input in as a string
disp function
displays text and variables into the command window