How can I define some initialization commands in a s-function block in Simulink depending on a declarated variable from the Matlab command window ?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi, I have a subsystem masked in Simulink which contains initialization commands that are used depending on a declared variable from the Matlab command window (called Bcaso) - I converted my subsystem into a s-function block, which does not depend on Bcaso. I need that my s-function block can be executed depending on Bcaso. Thanks!
댓글 수: 0
채택된 답변
Seth Popinchalk
2011년 2월 2일
S-functions can include parameter inputs. There are examples of this for Level 2 MATLAB S-function, (msfcndemo_limintm) and C-MEX S-functions, (see sfundemos).
In a Level 2 MATLAB S-function, during "setup" set the number of dialog parameters:
block.NumDialogPrms = 3;
Anywhere you need to reference a parameter (for example) inside "InitConditions" you can access it through the block object:
block.ContStates.Data = block.DialogPrm(3).Data;
The parameters are passed into the block through the S-function block parameters, separated by commas.
For C-MEX S-functions, use ssSetNumSfcnParams in mdlInitializeSizes to set the number of parameters and ssGetSfcnParam to get a pointer to an mxArray anywhere you need to use it. C-MEX S-functions also need to do some parameter checking, so it can get a lot more complicated. See the SFCNDEMOS for examples.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!