Matlab Functions Quiz

Matlab
0 Passed
0% acceptance

35 essential questions on using built-in functions, understanding inputs/outputs, accessing documentation, and creating anonymous functions.

35 Questions
~70 minutes
1

Question 1

What is the correct syntax to call a function named 'myFunc' with input 'x' and store the result in 'y'?

A
y = myFunc(x)
B
myFunc(x) -> y
C
call myFunc(x) as y
D
y = call(myFunc, x)
2

Question 2

How do you capture two output arguments from a function, such as 'max'?

A
[val, idx] = max(v)
B
val, idx = max(v)
C
(val, idx) = max(v)
D
{val, idx} = max(v)
3

Question 3

Which command displays a brief summary of a function's usage directly in the Command Window?

A
help functionName
B
doc functionName
C
info functionName
D
man functionName
4

Question 4

What does the command 'doc plot' do?

A
Opens the Help Browser with detailed documentation for 'plot'
B
Prints a short text summary in the console
C
Plots a document icon
D
Creates a new documentation file
5

Question 5

How do you define an anonymous function that squares its input?

A
sqr = @(x) x.^2;
B
sqr = function(x) { return x^2; }
C
sqr(x) = x^2;
D
def sqr(x): return x^2
6

Question 6

Which of the following is a valid name for a user-defined function?

A
calculate_area
B
2calculate
C
calculate-area
D
calculate area
7

Question 7

If a function returns two values but you only want the second one, how can you ignore the first?

A
[~, result] = func()
B
[_, result] = func()
C
[0, result] = func()
D
[, result] = func()
8

Question 8

What happens if you call a function with fewer inputs than it expects (and it doesn't handle defaults)?

A
It throws an error: 'Not enough input arguments'
B
It assumes the missing inputs are 0
C
It prompts the user to enter them
D
It runs with 'NaN' for missing inputs
9

Question 9

What is the data type of 'f' in 'f = @(x) x+1'?

A
function_handle
B
string
C
double
D
object
10

Question 10

Can an anonymous function contain multiple statements or loops?

A
No, it must be a single executable expression
B
Yes, if separated by semicolons
C
Yes, if enclosed in braces
D
Only if it uses 'if' statements
11

Question 11

Which built-in variable inside a function tells you how many input arguments were passed?

A
nargin
B
ninput
C
args.length
D
count
12

Question 12

How do you call a function that requires no inputs?

A
funcName() or just funcName
B
funcName[]
C
call funcName
D
@funcName
13

Question 13

What is the maximum length of a function name in MATLAB?

A
63 characters
B
31 characters
C
255 characters
D
Unlimited
14

Question 14

If you have a function handle 'h', how do you evaluate it with input 5?

A
h(5)
B
eval(h, 5)
C
run(h, 5)
D
h.execute(5)
15

Question 15

Which command lists all functions in the current folder?

A
what
B
list
C
funcs
D
show
16

Question 16

Can you define a function inside a script file?

A
Yes, but it must be at the end of the file (Local Function)
B
No, functions must be in their own files
C
Yes, anywhere in the file
D
Only if the script is empty
17

Question 17

What is the purpose of 'varargin' in a function definition?

A
To accept a variable number of input arguments
B
To define a variable globally
C
To validate arguments
D
To return variable arguments
18

Question 18

Which function allows you to find the path of a built-in function file?

A
which functionName
B
where functionName
C
path functionName
D
find functionName
19

Question 19

What is the scope of variables defined inside a standard function?

A
Local to that function (they disappear after execution)
B
Global (accessible everywhere)
C
Persistent (saved between calls)
D
Shared with the base workspace
20

Question 20

How do you create an anonymous function with two inputs, x and y?

A
f = @(x, y) x + y;
B
f = @(x; y) x + y;
C
f = @(x) @(y) x + y;
D
f = (x, y) => x + y;
21

Question 21

What does 'lookfor keyword' do?

A
Searches the first comment line of all functions for the keyword
B
Searches the internet for the keyword
C
Finds a variable in the workspace
D
Looks for a file named keyword
22

Question 22

Which symbol is used to separate multiple output arguments in a function definition?

A
Commas: function [a, b] = myFunc()
B
Semicolons: function [a; b] = myFunc()
C
Spaces: function [a b] = myFunc()
D
Colons: function [a: b] = myFunc()
23

Question 23

If you define 'a = 5' in the Command Window, can an anonymous function 'f = @(x) x + a' use 'a'?

A
Yes, it captures the value of 'a' at the time of creation
B
No, anonymous functions have no scope
C
Yes, but it updates if 'a' changes later
D
Only if 'a' is global
24

Question 24

What is the primary difference between a Script and a Function?

A
Scripts share the base workspace; Functions have their own local workspace
B
Scripts are faster
C
Functions cannot save files
D
Scripts must start with the keyword 'script'
25

Question 25

Which naming convention is most commonly recommended for standard MATLAB functions?

A
camelCase or lowercase
B
Snake_Case
C
PascalCase
D
UPPERCASE
26

Question 26

What does the 'disp' function do?

A
Displays the value of a variable or string to the console
B
Disposes of a variable
C
Displays a graph
D
Disables warnings
27

Question 27

How can you pass a function as an argument to another function (e.g., to 'fplot')?

A
Pass the function handle: @sin
B
Pass the name as a string: 'sin'
C
Pass the result: sin(x)
D
Both A and B (depending on the function)
28

Question 28

What does 'nargout' allow you to do?

A
Check how many outputs the caller requested and adjust behavior
B
Set the number of outputs
C
Count input arguments
D
Output to a file
29

Question 29

Which keyword starts a function definition in a file?

A
function
B
def
C
func
D
define
30

Question 30

What is the result of 'feval(@sin, pi/2)'?

A
1
B
Error
C
pi/2
D
0
31

Question 31

Can a function name contain a period (e.g., 'my.func')?

A
No, periods are for struct fields or object methods
B
Yes, it's valid
C
Only if it's a package
D
Yes, if inside quotes
32

Question 32

What does the 'input' function do?

A
Prompts the user for input from the command line
B
Reads a file
C
Defines an input argument
D
Imports data
33

Question 33

If you want to create a function that accepts any number of inputs and returns their sum, which tool is essential?

A
varargin
B
inputParser
C
nargin
D
global
34

Question 34

What is a 'local function'?

A
A helper function defined in the same file as the main function, only accessible within that file
B
A function that only runs on the local machine
C
A function inside a loop
D
A variable named 'local'
35

Question 35

How do you access the documentation for a specific operator, like the colon operator?

A
help colon
B
help :
C
doc :
D
All of the above work

QUIZZES IN Matlab