Dynamically change the number of ports of a block

13 visualizzazioni (ultimi 30 giorni)
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 Commenti
grapevine
grapevine il 27 Feb 2012
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 il 28 Feb 2012
I guess they use this instruction
replace_block(gcs,'Inport','Ground','noprompt' );
right guess?

Accedi per commentare.

Risposta accettata

Kaustubha Govind
Kaustubha Govind il 27 Feb 2012
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 Commenti
grapevine
grapevine il 28 Feb 2012
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 il 6 Mar 2012
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;

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by