Bird
Raised Fist0
MATLABdata~20 mins

Signal routing in MATLAB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Signal Routing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this signal routing code?
Consider the following MATLAB code that routes signals through a switch matrix. What will be the value of outputSignal after execution?
MATLAB
inputSignal = [1 2 3 4];
switchMatrix = [0 1 0 0; 1 0 0 0; 0 0 0 1; 0 0 1 0];
routeIndex = 2;
outputSignal = inputSignal * switchMatrix(routeIndex, :)';
A1
B2
C[2]
D1 0 0 0
Attempts:
2 left
💡 Hint
Remember that MATLAB matrix multiplication rules apply and the switchMatrix row selects which inputSignal elements are routed.
🧠 Conceptual
intermediate
1:30remaining
Which statement correctly describes signal routing in MATLAB?
In MATLAB, when routing signals using matrices, which of the following statements is true?
ASignal routing is achieved by multiplying the input signal vector by a routing matrix that acts as a selector.
BSignal routing can be done by element-wise multiplication of input and routing matrices.
CSignal routing requires loops to assign each input to output manually.
DSignal routing is only possible using Simulink, not MATLAB code.
Attempts:
2 left
💡 Hint
Think about how matrix multiplication can select and combine signals.
🔧 Debug
advanced
2:00remaining
Identify the error in this signal routing code
The following MATLAB code is intended to route signals from inputSignal to outputSignal using routingMatrix. What error will occur when running this code?
MATLAB
inputSignal = [1 2 3];
routingMatrix = [0 1 0; 1 0 0];
outputSignal = inputSignal * routingMatrix;
ANo error; outputSignal will be [2 1 0].
BDimension mismatch error due to incompatible matrix sizes for multiplication.
CRuntime error because routingMatrix contains zeros.
DSyntax error due to missing semicolon.
Attempts:
2 left
💡 Hint
Check the sizes of the matrices involved in multiplication.
❓ Predict Output
advanced
2:00remaining
What is the output of this complex routing example?
Given the following MATLAB code, what is the value of outputSignal?
MATLAB
inputSignal = [10 20 30 40];
routingMatrix = [1 0 0 0; 0 0 1 0; 0 1 0 0; 0 0 0 1];
outputSignal = routingMatrix * inputSignal';
A[40; 20; 30; 10]
B[10 30 20 40]
C[10; 30; 20; 40]
D[10; 20; 30; 40]
Attempts:
2 left
💡 Hint
Remember that inputSignal is a row vector and is transposed to a column vector before multiplication.
🚀 Application
expert
1:30remaining
How many output signals are produced by this routing matrix?
Given the routing matrix below, how many output signals will be generated when routing an input vector of length 5?
MATLAB
routingMatrix = [1 0 0 0 0;
                 0 1 0 0 0;
                 0 0 1 0 0;
                 0 0 0 1 0];
A0
B5
C1
D4
Attempts:
2 left
💡 Hint
The number of output signals corresponds to the number of rows in the routing matrix.

Practice

(1/5)
1. What is the main purpose of signal routing in MATLAB programming?
easy
A. To send data to different parts of a program based on conditions
B. To create graphical user interfaces
C. To perform mathematical calculations only
D. To store data permanently on disk

Solution

  1. Step 1: Understand signal routing concept

    Signal routing means directing data flow to different parts depending on conditions.
  2. Step 2: Match purpose with options

    Only To send data to different parts of a program based on conditions describes sending data based on conditions, which is signal routing.
  3. Final Answer:

    To send data to different parts of a program based on conditions -> Option A
  4. Quick Check:

    Signal routing = conditional data flow [OK]
Hint: Signal routing controls data flow based on conditions [OK]
Common Mistakes:
  • Confusing signal routing with data storage
  • Thinking it only does calculations
  • Mixing it up with GUI creation
2. Which of the following is the correct syntax to route a signal based on a condition in MATLAB?
easy
A. if signal > 0 { output = signal; } else { output = 0; }
B. if (signal > 0) then output = signal else output = 0 end if
C. if signal > 0 output = signal; else output = 0; end
D. if signal > 0: output = signal else: output = 0

Solution

  1. Step 1: Recall MATLAB if-else syntax

    MATLAB uses 'if condition', statements, 'else', statements, and 'end' to close.
  2. Step 2: Compare options with MATLAB syntax

    if signal > 0 output = signal; else output = 0; end matches MATLAB syntax exactly; others use syntax from other languages.
  3. Final Answer:

    if signal > 0 output = signal; else output = 0; end -> Option C
  4. Quick Check:

    MATLAB if-else ends with 'end' [OK]
Hint: MATLAB if-else blocks end with 'end' keyword [OK]
Common Mistakes:
  • Using 'then' keyword (not in MATLAB)
  • Using braces {} instead of end
  • Using colons like Python
3. What will be the output of this MATLAB code?
signal = -5;
if signal > 0
    routed = 1;
else
    routed = -1;
end
routed
medium
A. -1
B. 1
C. 0
D. Error

Solution

  1. Step 1: Check the condition signal > 0

    signal is -5, which is not greater than 0, so condition is false.
  2. Step 2: Follow else branch

    Since condition is false, routed is assigned -1.
  3. Final Answer:

    -1 -> Option A
  4. Quick Check:

    signal = -5 -> routed = -1 [OK]
Hint: Check condition truth to pick if or else branch [OK]
Common Mistakes:
  • Assuming negative numbers satisfy > 0
  • Confusing output variable name
  • Expecting zero output
4. Identify the error in this MATLAB signal routing code:
signal = 10;
if signal > 5
    output = 1;
else
    output = 0;
medium
A. Variable 'output' is not defined
B. Missing 'end' to close the if statement
C. Incorrect comparison operator
D. Using semicolons incorrectly

Solution

  1. Step 1: Check if statement structure

    MATLAB requires 'end' to close if blocks.
  2. Step 2: Verify code completeness

    The code lacks 'end' after else block, causing syntax error.
  3. Final Answer:

    Missing 'end' to close the if statement -> Option B
  4. Quick Check:

    if blocks must end with 'end' [OK]
Hint: Always close if with 'end' in MATLAB [OK]
Common Mistakes:
  • Forgetting 'end' after if-else
  • Thinking semicolons end blocks
  • Misusing comparison operators
5. You want to route a signal in MATLAB to three different outputs based on its value:
- If signal < 0, output = -1
- If signal == 0, output = 0
- If signal > 0, output = 1
Which code correctly implements this routing?
hard
A. if signal < 0 output = -1; else if signal == 0 output = 0; else output = 1; end
B. if signal <= 0 output = -1; elseif signal == 0 output = 0; else output = 1; end
C. if signal < 0 output = -1; if signal == 0 output = 0; else output = 1; end
D. if signal < 0 output = -1; elseif signal == 0 output = 0; else output = 1; end

Solution

  1. Step 1: Understand routing conditions

    We need three cases: less than 0, equal to 0, greater than 0.
  2. Step 2: Check code correctness

    if signal < 0 output = -1; elseif signal == 0 output = 0; else output = 1; end uses if, elseif, else correctly with proper conditions and 'end'.
  3. Step 3: Identify errors in other options

    if signal <= 0 output = -1; elseif signal == 0 output = 0; else output = 1; end wrongly uses <= which overlaps conditions; C uses two separate ifs causing logic errors; D uses 'else if' which is invalid syntax in MATLAB.
  4. Final Answer:

    if signal < 0 output = -1; elseif signal == 0 output = 0; else output = 1; end -> Option D
  5. Quick Check:

    Use if-elseif-else for multiple conditions [OK]
Hint: Use if-elseif-else for multiple exclusive conditions [OK]
Common Mistakes:
  • Using overlapping conditions like <= and ==
  • Using nested if without else properly
  • Writing 'else if' instead of 'elseif'
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard