Dynamically change the number of ports of a block

조회 수: 10 (최근 30일)
grapevine
grapevine 2012년 2월 27일
Hello everyone,
I'm looking for a way to build a Simulink block, where the number of port is defined by the user, e.g. a mask allows the user to define by using a popup the number of input port of the block.
Is there any way to do that ? I know I can define inside a s-function the number of ports
%%Register number of input and output ports
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
but is that the only solution available?
thanks a lot
  댓글 수: 2
grapevine
grapevine 2012년 2월 27일
because an image is worth thousand words
take a look at that
http://blogs.mathworks.com/seth/2008/08/13/dynamic-mask-dialogs/#comment-1732
how do they dynamically update the number of input?
do They pass a parameter to a sfunction or not?
grapevine
grapevine 2012년 2월 28일
I guess they use this instruction
replace_block(gcs,'Inport','Ground','noprompt' );
right guess?

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

채택된 답변

Kaustubha Govind
Kaustubha Govind 2012년 2월 27일
Have you tried setting the number of input ports based on the parameter value? For example, try something like:
block.NumInputPorts = block.DialogPrm(3).Data;
  댓글 수: 3
grapevine
grapevine 2012년 2월 28일
I made it, here is the code :
"
% Register number of parameters
block.NumDialogPrms = 1;
% Register number of input and output ports
block.NumInputPorts = block.DialogPrm(1).Data;
block.NumOutputPorts = 1;
"
but this solution involves a L2 mfile sfucntion and I need to write a L2 C file sfunction
Any suggestion to do that, will be very appreciated
Kaustubha Govind
Kaustubha Govind 2012년 3월 6일
Not sure, but you could try extending the same logic to C S-functions by using similar code in mdlInitializeSizes.
const mxArray* prm1 = ssGetSFcnParam(S, 0);
int_T nInputPorts = (int_T)(mxGetPr(prm1)[0]); //assuming param is a double value
if (!ssSetNumInputPorts(S,nInputPorts)) return;

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by