Question
[Context] I want to simulate a complex system many times in order to calculate the average behaviour of the system and I want to avoid the many compilations that would occur in a loop containing the sim(mdl) command. Notice that the only thing changing between each simulation of the system is the input signal values... [Situation] Let’s take a very simple example to be clear : Create a new model with a “Sine Wave” block with the following parameters : Sine Type : Time-based (Default) Time (t) : Use simulation Time (Default) Amplitude : [ 1 1 1 ] Bias : [ 0 0 0 ] Frequency : [1 1 1 ]*2*pi*0.22 Phase : rand(1,3) %Here is the only param that changes between simulations Sample Time: 0 [Uncheck] Interpret vector parameters as 1-D Add a “Transfer Fcn” block with the following parameters (for example) : Numerator : [1] Denominator : [1 0 1] (Others to default value) Connect the “Sine Wave” block to the “Transfer Fcn” block and the output of the “Transfer Fcn” to a “Scope” block. No need to change Configuration Parameters of simulation (Stop time etc...) [Aim] Instead of running the simulation many times with one sinewave I want to exploit the possibility of generating many (=3 here) sinewaves once and run only one simulation... [Problem] The simulation throws errors : “Error in port widths or dimensions.[...]” I know that the “Transfer Fcn” block does not feature Scalar expansion so do you have a solution to this problem or a workaround that avoids the repetitive compilations of the model ?
Related Questions
Expert Answer
Kshitij Singh
PhD Expert
Answered Nov 20, 2025
I tested a model and found problems doing what you want, my workaround is:
- Insert a sine wave block (f=2*pi*0.22 and phase=rand), tf block (your num and den)
- Insert one mux block (three inputs) and the scope
- Now copy and paste the sine wave block two times
- Do the same for the transfer function block (paste it two times)
- Connect the sine waves to each transfer function block
- Connect the transfer functions outputs to the mux and the mux to the scope
Now with just one simulation you get three waves
Have a different question? Ask here