S-Function Block and Masking Parameters

조회 수: 8 (최근 30일)
Atit
Atit 2014년 6월 19일
댓글: Kaustubha Govind 2014년 6월 26일
I have created an S-function (Level2) and included a callback function in its 'OpenFcn' under Block Properties. This callback reads an xls file and assigns data read to the S-Function parameters (variables). I would like perform the following items: 1) Display the data read at respective Mask Parameters of the S-Function block 2) Based on the data read, change the number of input and output port of the S-function block. (Example, if suppose there are 3 rows of data in the xls, the number of input ports will be 3). Any help or ideas on this would be greatly appreciated.
Atit

채택된 답변

Kaustubha Govind
Kaustubha Govind 2014년 6월 20일
To set the number of inputs/outputs based on parameter values, you can add code such as the following to your setup function:
block.NumInputPorts = block.DialogPrm(1).Data;
block.NumOutputPorts = block.DialogPrm(2).Data;
You can display the value of the parameters using block.DialogPrm(idx).Data
  댓글 수: 2
Atit
Atit 2014년 6월 26일
Thanks Kaustubha. I will have try your suggestions and see if that's what I was looking for. Else, I will have to re-frame my question :).
Otherwise, I have few other queries as well specifically on S-functions.
1) What does this datatype int_T corresponds to? If I have a value lets say as 203.65 and its typecasted as (int_T)203.65, then what should be outcome? Does this rounds and fixes it? (i.e. it may possibly become 203?) I am having some challenges dealing with this and similar datatypes used on of the S-functions. This is peculiar, as it doesn't imply if its similar to int32_T (!!).
2) Does this function mxGetPr returns pointer to a pointer as in C? (i.e. **ptr)? If this so, can we use this interchangebly? Some of my queries including the above once could have resolved if there is simple ways to debug an S-functions (without any other third party tool/Software), but I don't to debug them. Still figuring out.... Regard Atit
Kaustubha Govind
Kaustubha Govind 2014년 6월 26일
  1. AFAIK, int_T is defined as int32_T on 32-bit machines and int64_T on 64-bit machines. It is used to maintain platform independence (see What are the real_T and int_T datatypes referenced in the Simulink template CMEX S-function?)
  2. You must use mxGetPr only for double arrays (default type in MATLAB) only. This returns a double-pointer as documented.
There is no built-in debugger for S-functions because they are essentially shared libraries (DLLs) with a predefined format - the binary format itself depends on the MEX compiler that is used and is not MATLAB-specific. This is why we recommend debugging with your C compiler tools.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by