Home > Flashcards > Print Preview
The flashcards below were created by user
Anonymous
on FreezingBlue Flashcards. What would you like to do?

who
Shows variables that have been defined in this Command Window (just shows the names of the variables).

whos
Shows variables that have been defined in this Command Window (this shows more information on the variables, similar to what is in the Workspace Window).

clear
Clears out all variables so they no longer exist.

clear variablenames
Clears out a particular variable.

abs(variable)
Absolute value of that number or variable.

fix(variable)
Round towards zero.

floor(variable)
Round towards minus infinity.

ceil(variable)
Round towards positive infinity.

round(variable)
Round to nearest integer.

sign(variable)
Returns 1 if number greater than zero; returns 0 if it is zero; returns 1 if less than zero.

rem(num,div)
Returns the remainder from division (first number divided by the second number).

char, logical, int32, double
char = used to store single characters or strings; logical = used to store true/false values; int32 = integer with max 32 bits; double = real number, can use floating point.

rand
Generates a random real number from 01.

How to generate a random integer in the range of xy.
round(rand*(yx))x

How to create a row vector or column vector
 Row vec: v = [1 2 3 4] or [1:4]; for steps, use colon operator.
 Column vec: v = [1;2;3;4]

How to refer to an element in (a) a vector (b) a matrix?
 a) myvec(element#)
 b) mymat(row#,column#)  can refer to subsets of matrices (ex: mymat(1:2,2:3)). If a single index is used (ex: mymat(1)), it unwinds the matrix columnwise (goes down row by row until the next column).

How to create a matrix.
mat = [4 3 1; 2 5 6; 3:5]

zeros(rows, columns) ; zeros(#)
ones(rows, columns); ones(#)
Creates a matrix of zeroes (or ones) of the given dimensions; if only one number is given, that will be the number of rows and columns.

length(variable)
Gives the number of elements in a vector and the length of the largest dimension (either rows or columns) in a matrix.

size(variable)
Returns the numbers of rows and columns in a matrix (rows first, then columns).

numel(variable)
Returns the total number of elements in an array (vector or matrix).

variable(end,#)
end refers to the last element in a vector. vec(end) = vec(length(vec)). In a matrix, it can refer to the last element in a row or column. Ex: mymat(end,1) returns the last element of the first row and first column.

reshape(variable,rows,columns)
Iterates through the matrix columnwise and returns a new matrix with the new dimensions.

fliplr(variable)
Flips the matrix from left to right; the leftmost column becomes the last column and so forth.

flipud(variable)
Flips up to down. Works from outsides in. (1st becomes last, 2nd becomes 2nd to last, etc.)

rot90(variable)
Rotates the matrix counterclockwise 90 degrees. The topright value becomes the topleft value; last column becomes the first row.

repmat(variable,m,n)
Creates a larger matrix, which consists of an m x n matrix of copies of the matrix named in the function call. Ex: a 2 x 2 matrix when called in repmat(mat,2,3) becomes a 6 x 4 matrix with repetitions of the original 2 x 2.

Empty vector
[ ]; a vector that stores no values, created using empty brackets.

