필터 지우기
필터 지우기

Level-2 S-Function in Simulink subsystem

조회 수: 3 (최근 30일)
David Gallarta
David Gallarta 2021년 1월 15일
답변: Anshuman 2024년 6월 20일
I'm working with a Level-2 S-Function in a Simulink subsystem and I would like to configure some parameters (IP, sample time) from the subsystem mask so that I don't have to edit the Matlab code on every change, defining them into the S-Function as a variable. How can these parameters be passed to the S-Function?
The error I get is: "Cannot access data in 'simulink_pr/Subsystem/ '. The probable cause of this error is accessing data that is available only when simulation is running"
Thank you very much

답변 (1개)

Anshuman
Anshuman 2024년 6월 20일
Hello,
To configure parameters such as IP address and sample time from a Simulink subsystem mask into a Level-2 MATLAB S-Function, you need to use mask parameters. These mask parameters allow you to change the S-Function's behavior without modifying the MATLAB code directly for each change.
  1. Open your Simulink model and navigate to the subsystem that contains your S-Function.
  2. Right-click on the subsystem block and select Mask -> Create Mask.
  3. In the Mask Editor, go to the Parameters & Dialog tab.
  4. Add parameters that you want to pass to the S-Function, such as IP address and sample time. Set the Name, Type, and Prompt for each parameter. The 'Name' is used in the MATLAB code to access the parameter value.
In your Level-2 MATLAB S-Function, you can access these parameters using the 'Simulink.Parameter' object or directly within the S-Function code.
blockIP = get_param(block.BlockHandle, 'ip_parameter_name');
blockSampleTime = str2double(get_param(block.BlockHandle, 'sample_time_parameter_name'));
After retrieving the parameters, you can use these values throughout your S-Function.

카테고리

Help CenterFile Exchange에서 Block and Blockset Authoring에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by