From bf2b9d08063578f25fe1cc90b31e7545f0bf524d Mon Sep 17 00:00:00 2001 From: ehudbehar Date: Mon, 27 Sep 2021 22:16:28 +0300 Subject: [PATCH] Add 8 Matlab questions (#2270) Improved formatting in q54 and add 8 question in Matlab-quiz.md Co-authored-by: Zhenja --- matlab/matlab-quiz.md | 74 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/matlab/matlab-quiz.md b/matlab/matlab-quiz.md index 33a3a76b3f..eb20f3f53d 100755 --- a/matlab/matlab-quiz.md +++ b/matlab/matlab-quiz.md @@ -819,12 +819,14 @@ a = a^2; #### Q54. Which choice is the correct syntax for declaring a function that returns the input value as the output? +- [ ] + ``` function mystery_func(a) : return a ``` -- [ ] +- [x] ``` function b = mystery_func(a) @@ -832,7 +834,7 @@ function b = mystery_func(a) end ``` -- [x] +- [ ] ``` def b = mystery_func(a) @@ -849,8 +851,6 @@ function mystery_func(a) end ``` -- [ ] - [Reference](https://mathworks.com/help/matlab/ref/function.html) #### Q55. What is the state of a at the end of this code? @@ -902,3 +902,69 @@ a = - [x] `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]);` + +#### Q57. Which statement will return all the odd numbers from 1 to 9? + +- [ ] `2*[1:5]+1` +- [x] `1:2:9` +- [ ] `isodd(1:9)` +- [ ] `1:odd:9` + +#### Q58. 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 = ones(5,5)/25; +imshow(imfilter(img,h)); +``` +- [ ] `h` is a Gaussian filter that adds to 1. Its intended effect is to highlight image edges. +- [x] `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. + +#### Q59. What is the size of `b`? + +``` +a = [1 2 3]; +b = repmat(a,2,3); +``` + +- [ ] 1x3 +- [ ] 3x2 +- [ ] 2x3 +- [x] 2x9 + +#### Q60. Which statement reverses vector `a`? + +``` +a = [ 1 2 3 4]; +``` + +- [ ] reverse(a) +- [x] a(end:- 1:1) +- [ ] rev(a) +- [ ] a(::-1) + +#### Q61. Which command will create a column vector with the values 7, 8, and 9? + +- [ ] `c = [7,8,9]` +- [ ] `c = [7: 8: 9]` +- [x] `c = [7; 8; 9]` +- [ ] `c = [7 8 9]` + +#### Q62. What do you call in the **command** window to see all the variables in the workspace and their classes? +- [ ] `who` +- [ ] `vars` +- [x] `whos` +- [ ] `who all` + +#### Q63. 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? +- [x] which +- [ ] who +- [ ] lookfor +- [ ] what + +#### Q64. 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 +- [x] to include a variable greater that 2GB +- [ ] to use compression by default