Dynamically change the number of ports of a block

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 日

0 投票

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 日
Thanks for the advice, I'll try but actually I have to write a L2 S-function with C I'm wondering if I can use the same instructions, same structure like Block, or I have to replace the structure Block with SimStruct *S.
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 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by