How to put variable name in Y-limits of a scope in Simulink programmatically from Matlab

P
priya · Oct 4, 2021 · 2K views
Question
I want to put variables names in the Y-limits of a scope in Simulink( v10) with Matlab (v2019b). To be able to control the Y-limits of my scopes with variables associated to the thing i'm measuring.   I can do it with the GUI via the Y-limits (minimum) and Y-limits (maximum) but the value stored in Y-limits (when i do "get_param(path,'scopeconfiguration')") is the vector with the numerical value.   But when I try to do it programmaticall, I can't put variable names. As it only accept 2-element finite numeric vector.
Expert Answer
Profile picture of Neeta Dsouza
Neeta Dsouza PhD Expert
Answered Aug 24, 2026

To set variable names as the Y-limits of a Scope in Simulink programmatically from MATLAB, you can follow these steps:

1. Define the Variable:
   First, define your variable with the desired Y-limits.

   
   Ymin = -10;  % Minimum Y-limit
   Ymax = 10;   % Maximum Y-limit
   

2. Get the Scope Block Handle:
   Obtain the handle for the Scope block in your Simulink model.

   
   scopeBlock = get_param('your_model/Scope', 'Handle');
   

3. Set the Y-Limits Programmatically:
   Use the `set_param` function to set the Y-limits of the Scope block.

   
   set_param(scopeBlock, 'YMin', 'Ymin', 'YMax', 'Ymax');
   

Putting it all together, the complete code would look like this:

% Define the variables
Ymin = -10;  % Minimum Y-limit
Ymax = 10;   % Maximum Y-limit
% Get the Scope block handle
scopeBlock = get_param('your_model/Scope', 'Handle');
% Set the Y-limits programmatically
set_param(scopeBlock, 'YMin', 'Ymin', 'YMax', 'Ymax');
Replace `'your_model/Scope'` with the actual path to your Scope block in the Simulink model.

This will set the Y-limits of the Scope block to the values defined in `Ymin` and `Ymax`.

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!