0
0
MATLABdata~10 mins

Anonymous functions in MATLAB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an anonymous function that squares its input.

MATLAB
square = [1] x^2;
Drag options to blanks, or click blank then click option'
A@(x)
Bfunction
Clambda
Ddef
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'function' keyword instead of '@(x)'
Trying to use Python or other language syntax like 'lambda' or 'def'
2fill in blank
medium

Complete the code to create an anonymous function that adds 5 to its input.

MATLAB
addFive = [1] x + 5;
Drag options to blanks, or click blank then click option'
A@(x)
Bfunction
Clambda
Ddef
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the '@' symbol
Using other language syntax like 'lambda'
3fill in blank
hard

Fix the error in the anonymous function that multiplies input by 3.

MATLAB
triple = [1] x * 3;
Drag options to blanks, or click blank then click option'
Alambda
Bfunction
C@(x)
Ddef
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'function' keyword
Using Python syntax like 'lambda' or 'def'
4fill in blank
hard

Fill both blanks to create an anonymous function that returns true if input is greater than 10.

MATLAB
isGreaterThanTen = [1] x [2] 10;
Drag options to blanks, or click blank then click option'
A@(x)
B==
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality operator instead of greater than
Omitting the '@(x)' part
5fill in blank
hard

Fill all three blanks to create an anonymous function that returns true if input is between 5 and 15 (inclusive).

MATLAB
isBetween = [1] x [2] 5 && x [3] 15;
Drag options to blanks, or click blank then click option'
A@(x)
B>=
C<=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using strict greater than or less than instead of inclusive operators
Omitting the '@(x)' syntax