It depends on the blocks you are working with. For example, in your case of a Multiport Switch, this is possible. Simply connect the first inport with a constant block. The value of the constant block will determine the number of inputs for the Multiport Switch. The value of the Constant block can be extracted as follows:
I am attaching the screenshot "testModel.png" for your reference.