Documente Academic
Documente Profesional
Documente Cultură
To best prepare for the exam, do as many practice exams as you can. This review guide is not a
completely exhaustive list.
Topics:
• Function Headers and Conceptual Questions
• Basic Function Operations
• Vectors/Strings and their functions
• Numerical Indexing
• Logical Indexing/Masking
• Arrays
Function Headers:
Examples of Valid Function Headers
function out = myfunc(in)
function [out] = functionName(in)
function [a b] = func(in, in2)
function name(in)
function name()
function name
function a = name()
function [] = name()
Be able to define/describe:
• Function Scope
• Encapsulation
• Abstraction
• Hard Coding
• Helper Functions
• Dimension Mismatch
• Indexing Out of Bounds
• Function Operations:
char() vs. num2str() >> char converts a double into its corresponding
character letter ( 65 à ‘A’) while num2str coverts a double into the
character of that number (65 à ‘65’)
Vectors/Strings
Indexing
Numerical Indexing: simply say which index of the vector/ string you want to
access
“Store the third value of vec in a variable named a”
a = vec(3)
“Store the first and third values of vec in a variable named b”
b = vec([1,3]) ß multiple indices must be kept in brackets
vec(1,3) is wrong
“Store every other value of vec in a variable named c”
c = vec(1:2:end)
Creating Vectors
Manual Entry: [1 3 5 7]
Colon Operator: 1:2:7
Using different functions: linspace(starting num, ending numb, steps)
ones(rows, columns)
zeros(rows, columns)
Logical Indexing
Creating and using a mask
“Find all the values greater than 10 in vec”
mask = vec > 10
“Find all the values greater than 10 in vec and replace them with 0”
mask = vec > 10
vec(mask) = 20
“Find all the values greater than 10 in vec and add 5 to those values only”
mask = vec > 10
vec(mask) = vec(mask) + 5
“Find all the values in vec divisible by 10 and store these values in a”
mask = mod(vec,10) == 0
a = vec(mask)
any() à if any value is true, will return true, otherwise will return false
vec = [false true false false]
a = any(vec)
a = true
Arrays
Indexing
Must always, at least for this test, index arrays by using two values, rows and
columns
b = arr(:,3) ß finds values from all the rows, third column (aka, accesses
the third column)
c = arr(2, :) ß finds values in second row, all the columns (aka 2nd row)
Sorting arrays.
“Sort the array based off of the values in the first row in descending order”
[~ , ind] = sort(arr(1,:), ‘descend’);
arr = arr(:, ind); ß When you rearrange an array based off of values
in a specific row, the indices you find from sorting
are used to rearrange the columns. The order of
the rows doesn’t change.
“Sort the array based off of the values in the third column in ascending order”
[~ , ind] = sort(arr(:,3));
arr = arr(ind, :); ß When you rearrange an array based off of values
in a specific column, the indices you find from sorting
are used to rearrange the rows. The order of the columns
doesn’t change.