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

Illustration
priya - 2021-10-04T12:36:11+00:00
Question: How to put variable name in Y-limits of a scope in Simulink programmatically from Matlab

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 answered . 2025-11-20

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`.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!