Questions and Answers
- From what distribution does the `rand()` function return value?
- normal
- poisson
- binomial
- uniform
- Based on the code below, c is the \_ of a.
- median
- mode
- mean
- margin
- What does the Profiler track?
- execution time
- command history
- errors
- the value of variables
- Which code block contains the correct syntax for a `while` loop?
- [ ]
- [ ]
- [ ]
- [x]
- What does `b` contain?
- [x]
- [ ]
- You have written a function `myfun` and want to measure how long it takes to run. Which code segment will return in `t` the time in seconds it takes `myfun` to run?
- [ ]
- [x]
- [ ]
- [ ]
- What is `%%` used for?
- argument placeholder
- block quotes
- code sections
- conversion specifier
- what is the `.` character NOT used for?
- structure field access
- a decimal point
- cell array access
- element-wise operations
- Which function could you use for multiple linear regression?
- polyval
- regress
- solve
- polyfit
- For which of these arrays do `mean`, `median`, and `mode` return the same value?
- [0 1 1 1 2]
- [1 3 5 5 6]
- [0 1 1 1 1]
- [0 0 5 5 5]
- You are in the middle of a long MATLAB session where you have performed many analyses and made many plots. You run the following commands, yet a figure window doesn't pop up on the top of your screen with your plot. What might be the issue?
- Your plot doesn't plot in a figure window because `figure` was not called immediately in advance.
- Your `plot` syntax is incorrect.
- Your plot is in a figure window that was already open, hidden behind other windows on your screen.
- Your plot was saved to an image file but not displayed.
- How do you access the value for the field `name` in structure S?
- S['name']
- S.name
- S('name')
- S{'name'}
- What built-in definition does i have?
- basic imaginary unit
- index function
- infinity
- index variable
- Which statement is equivalent to this for loop?
- b = a\*a;
- b = a.^2;
- b = a^2;
- b = pow2(a);
- You have plotted values of cosine from -10 to 10 and want to change the x-axis tick marks to every pi, from -3*pi to 3*pi. Which statement will do that?
- xticks(-3*pi:3.14:3*pi)
- xticks(-3*pi:pi:3*pi)
- xticks(linespace(-3*pi(), 3*pi(), pi()))
- xticks(linespace(-3*pi, 3*pi, pi)
- What is the value of `c`?
- [-1 2 -1]
- [1 3 6 5 3]
- 6
- [1 -2 1]
- Which function CANNOT be used to randomly sample data?
- datasample
- randi
- resample
- randperm
- Which choice is correct syntax for a `switch` statement?
- [x]
- [ ]
- [ ]
- [ ]
- What is the result of this code?
- Error
- [ ]
- [x]
- [ ]
- What is true of a handle class object?
- When you pass a handle object to a function, a new object is made that is independent of the original.
- All copies of handle objects refer to the same underlying object.
- Handle object cannot reference one another.
- Handle object do not have a default `eq` function.
- Which choice has a different final result in `f10` than the other three?
- [ ]
- [ ]
- [x]
- [ ]
- Which choice will NOT give you a 5 x 5 identity matrix?
- [ ]
- [ ]
- [x]
- [ ]
- Which statement creates this structure?
- [ ]
- [x]
- [ ]
- [ ]
- `my_func` is a function as follows. What is the value of `a` at the end of the code beneath?
- 4
- 3
- 0
- 1
- Which statement could create this cell array?
- c = {"hello world" {"hello"} "goodbye" [1 2 ]};
- c = {"hello world" {"hello"} "goodbye" {[1 2 3]}};
- c = {"hello world" {"hello"} "goodbye" [1 2 3]};
- c = {"hello world" {"hello" "hello"} "goodbye" {[1 2 3]}};
- Which choice adds `b` to each row of `a`?
- a = a + reshape(b, 4, 1);
- a = a + b';
- a = a + repmat(b, 4, 1);
- a = a + [b b b b];
- Which choice replaces all `a`s with `o`s?
- [ ]
- [ ]
- [x]
- [ ]
- Which statement returns the roots for the polynomial `x^2 + 2x - 4`?
- poly([1 2 -4])
- solve(x^2 + 2x - 4 == 0)
- polyfit(x^2 + 2x - 4 == 0)
- roots([1 2 -4])
- Which choice is the proper syntax to append a new elements `a` to the end of 1x 2 dimensional cell array `C`?
- C = {C a};
- C = cellcat(C a)
- C = cat(2, {a}, C)
- C{end+1}=a
- You have loaded a dataset of people's heights into a 100 x 1 array called `height`. Which statement will return a 100 x 1 array, `sim_height`, with values from a normal distribution with the same mean and variance as your height data?
- sim_height = std(height) + mean(height) \* randn(100, 1);
- sim_height = mean(height) + std(height) \* randn(100, 1);
- sim_height = randn(std(height), mean(height), [100, 1]);
- sim_height = randn(mean(height), std(height), [100, 1]);
- Which statement returns a cell array of the strings containing '`burger`' from `menu`?
- menu{strfind(menu, 'burger')}
- menu(strfind(menu, 'burger'))
- menu{contains(menu, 'burger')}
- menu(contains(menu, 'burger'))
- What is the set of possible values that `a` may contain?
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
- 1, 2, 12
- 2, 11, 12
- 1, 12
- Which statement is true about the sparse matrices?
- You can use the `sparse` function to remove empty cells from cell array variables.
- Sparse matrices always use less memory than their associated full matrices.
- Mixtures of sparse and full matrices can be combined in all of MATLAB's built-in arithmetic operations.
- The `sparse` function requires its input to be a full matrix with at least 50% zero elements.
- Which statement using logical indices will result in an error?
- b = a(a ~= 11)
- b = a(a == 1)
- b = a(a>6 && a<9)
- b = a(a | 1)
- Which statement turns `menu` into the variable `menu_string` below?
- menu_string = cell2mat(join(menu, newline))
- menu_string = cell2mat(join(menu, '\n'))
- menu_string = join(menu, newline)
- menu_string = cell2mat(pad(menu))
- Which code snippet sets a new random seed based on the current time and saves the current settings of the random number generator?
- [x]
- [ ]
- [ ]
- [ ]
- You have a matrix `data` in which each column is mono audio recording from a room in your house. You've noticed that each column has a very different mean and when you plot them all on the same graph, the spread across the y axis make it impossible to see anything. You want to subtract the mean from each column. Which code block will accomplish this?
- [ ]
- [x]
- [ ]
- [ ]
- Which code block results in an array `b` containing the mean values of each array within `C`?
- [ ]
- [ ]
- [ ]
- [x]
- Which statement creates a logical array that is 1 if the element in `passwords` contains a digit and 0 if it does not?
- contains(password, '\d')
- ~isempty(regexp(passwords, '\d'))
- cellfun(@(x) ~isempty(regexp(x, '\d')), passwords)
- regexp(passwords, '\d')
- Which is NOT a function that adds text to a plot?
- title
- text
- label
- legend
- Which code block most likely produced this graph?
- [ ]
- [x]
- What kind of files are stored with the .mat extension?
- figure files
- script files
- function files
- stored variable files
- You would like to randomly reorder every element in array a and put the result into another array b. Which code is NOT necessary to do that?
- [x]
- [ ]
- [ ]
- [ ]
- Which statement returns **1** (true)?
- a == b
- ischar(b)
- length(a) == length(b)
- class(a) == class(b)
- Which does E contain?
- E = {'cat'} {'dog'}
- E = {'mouse'}
- E = {'cat'} {'cow'} {'dog'} {'piranha'}
- E =
- Where in the UI can you see what variables have been created, their values, and their class?
- Editor
- command window
- details
- workspace
- Given the following x and y coordinates, which choice calculates a linear regression for the x and y coordinates, and which plots the points of the x,y data and the regression line on the same graph?
- [x]
- [ ]
- [ ]
- [ ]
- If you run this piece of code, you will get an error. Why?
- You are attempting to multiply a non-square matrix by itself, causing a dimension mismatch.
- MATLAB does not allow you to square all the elements in the matrix in a single operation.
- You must use the \*\* operator instead of the ^ operator.
- You cannot square matrices that have a 0 as the first element.
- Which command will create a 10-element vector v with values from 1 to 10?
- v = {1:10}
- v = [1-10]
- v = 1:10
- v = (10)
- For a 5 x 5 array, the two subscript index (4,2) indexes the same location as linear index `___`.
- 7
- 8
- 17
- 9
- What is a difference between global variable and persistent variables?
- Global variables have a higher performance overhead than persistent variables.
- Global variables remain in memory after clear all; persistent variables do not.
- Global variables can be used to cache data in memory; persistent variables cannot.
- Global variables are accessible outside the function scope; persistent variables are not.
- How is the random seed for MATLAB's random number generator first initializedin a MATLAB Session?
- Seed is undefined until it is initialized by the user.
- Seed is set to a value based on the current time when user first calls rand()
- Seed is set to a value based on the current time on startup.
- Seed is set to a static default value on startup.
- At what will MATLAB look first for a called function?
- functions on the path
- built-in functions
- functions within the current file
- functions within the current directory
- Which choice is the correct syntax for declaring a function that returns the input value as the output?
- [ ]
- [x]
- [ ]
- [ ]
- What is the state of a at the end of this code?
- [ ]
- [x]
- [ ]
- [ ]
- You've just plotted some data and want to change the color behind the lines you've plotted to black. Which code block will accomplish this?
- `h_f = figure; set(h_f,'Color', [0 0 0]);`
- `h_a = gca; set(h_a,'Color', [0 0 0]);`
- `h_a = axes; set(h_a,'Color', [0 0 0]);`
- `h_f = gcf; set(h_a,'Color', [0 0 0]);`
- Which statement will return all the odd numbers from 1 to 9?
- `2*[1:5]+1`
- `1:2:9`
- `isodd(1:9)`
- `1:odd:9`
- In MATLAB, the `imfilter` command performs a convolution operation between an image and a matrix. Suppose you have an image loaded in MATLAB into the variable `img` and you apply the following code. The original image appears slightly blurred because the convolution smoothed out the image (removed noise). Why do you think this happened?
- `h` is a Gaussian filter that adds to 1. Its intended effect is to highlight image edges.
- `h` is an averaging filter uniformly distributed that adds to 1. Its intended effect is to smooth out images (remove noise).
- `h` is a Laplacian filter that adds up to 0. Its intended effect is to smooth out images (remove noise).
- `imfilter` is a function that always blurs the images.
- What is the size of `b`?
- 1x3
- 3x2
- 2x3
- 2x9
- Which statement reverses vector `a`?
- reverse(a)
- a(end:- 1:1)
- rev(a)
- a(::-1)
- Which command will create a column vector with the values 7, 8, and 9?
- `c = [7,8,9]`
- `c = [7: 8: 9]`
- `c = [7; 8; 9]`
- `c = [7 8 9]`
- What do you call in the **command** window to see all the variables in the workspace and their classes?
- `who`
- `vars`
- `whos`
- `who all`
- You wrote a new function named `snap` in an m-file and when you call it, you're not getting the output you expect. You previously wrote a different function named `snap`, which you think might also be on the search path. Which command can you use to see if the old `snap` function is being called?
- which
- who
- lookfor
- what
- What is a reason to save a MAT-file using the `-v7.3` flag?
- to ensure backward compatibility
- to avoid HDF5 overhead in MAT-file
- to include a variable greater that 2GB
- to use compression by default