Sink blocks (Scope, Display, To Workspace) in Simulink - Time & Space Complexity
We want to understand how the time to run a Simulink model changes when using sink blocks like Scope, Display, and To Workspace.
How does the amount of data affect the time these blocks take to process and show results?
Analyze the time complexity of this Simulink snippet that logs and displays signals.
% Simulink model setup
input_signal = rand(1, n); % input of size n
% Signal passes through some blocks
processed_signal = input_signal * 2;
% Sink blocks
% Scope(processed_signal);
% Display(processed_signal);
% ToWorkspace(processed_signal, 'out_data');
This code sends a signal of size n to three sink blocks that show or save the data.
Look at what repeats as input size grows.
- Primary operation: Each sink block processes every data point in the signal.
- How many times: Once per data point, so n times for input size n.
As the input size n grows, the sink blocks handle more data points one by one.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 operations |
| 100 | About 100 operations |
| 1000 | About 1000 operations |
Pattern observation: The work grows directly with the number of data points.
Time Complexity: O(n)
This means the time to process data in sink blocks grows linearly with the input size.
[X] Wrong: "Sink blocks process all data instantly, so time does not depend on input size."
[OK] Correct: Sink blocks handle each data point to display or save it, so more data means more work and more time.
Understanding how data size affects sink blocks helps you explain performance in simulations and data logging tasks.
What if we changed the sink block to log data only every 10th point? How would the time complexity change?
Practice
Solution
Step 1: Understand the purpose of Display block
The Display block shows numeric values updating live during simulation.Step 2: Compare with other sink blocks
Scope shows graphs, To Workspace saves data, Gain modifies signals, so they don't show live numbers directly.Final Answer:
Display block -> Option AQuick Check:
Live numeric value = Display block [OK]
- Confusing Scope with Display
- Thinking To Workspace shows live values
- Selecting Gain which is not a sink block
Solution
Step 1: Identify the save format options in To Workspace block
To Workspace block allows saving data as Array, Structure with time, Timeseries, or Matrix.Step 2: Choose the option that saves data as a structure
'Structure with time' saves data as a structure containing time and signals.Final Answer:
Set 'Save format' to 'Structure with time' -> Option CQuick Check:
Structure save format = 'Structure with time' [OK]
- Choosing 'Array' which saves plain arrays
- Confusing 'Timeseries' with structure
- Selecting 'Matrix' which is not a valid option
Signal -> To Workspace block (Save format: Array)
After simulation, what is the format of the saved data in MATLAB workspace?
Solution
Step 1: Understand 'Array' save format in To Workspace block
When 'Array' is selected, only the signal values are saved as a numeric array without time info.Step 2: Compare with other formats
Structure and Timeseries formats include time; cell arrays are not used here.Final Answer:
A numeric array containing signal values only -> Option AQuick Check:
Save format 'Array' = numeric array [OK]
- Assuming time is saved with Array format
- Confusing Array with Timeseries
- Expecting a structure instead of array
Solution
Step 1: Check Scope block connection
Scope requires a connected signal to display data; no connection means no graph.Step 2: Evaluate other options
Display block absence doesn't affect Scope; To Workspace format doesn't affect Scope display; simulation time zero means no data but usually simulation runs longer.Final Answer:
The Scope block is not connected to any signal -> Option DQuick Check:
Scope needs signal connection [OK]
- Thinking Display block affects Scope
- Confusing To Workspace settings with Scope display
- Ignoring signal connections
Solution
Step 1: Identify the sink block for saving data
To Workspace block is designed to save simulation data to MATLAB workspace for post-processing.Step 2: Choose the save format to include time
Setting 'Save format' to 'Structure with time' saves both signal data and time stamps.Final Answer:
Use To Workspace block; set 'Save format' to 'Structure with time' -> Option BQuick Check:
Save data with time = To Workspace + 'Structure with time' [OK]
- Using Display or Scope blocks to save data
- Choosing 'Array' format which lacks time info
- Not configuring save format properly
Ready to prove it?
Pass the test and this pattern moves unknown
