Issues with SImulink Output to a Vector.
9 vues (au cours des 30 derniers jours)
I was hoping someone could help me understand why I am getting different simulink results when passing a vector to a Simulink model. I have two models and am manually creating a BODE diagram and am passing a vector of frequencies to the Simulink model. The result is two 1x1 Simulation variables time series outputs for each frequency of the variable. It essentially runs the simulation for each value of the variable. However, one model is correct and the magnitude of the other model is incorrect. I know this because I have passed singular values as the variable and get different values. What I did to get the correct results for the second model was to index my simulation variable so it is now 1x100 and each index is a 1x1 simulation variable. So instead of passing a vector to simulink so it runs 100 times I am running 100 simulations. This is giving me the correct magnitude. I am wondering what is going on and if there is a way to pass a vector to simulink and get the correct results. My code is below for both what does not work, for one model, and what does work for all models.
This works for one model.
This works for both models.
for iii = 1:1:100; %Setting a loop to run simulations
DrivingForceFrequency=iii*.1; %Singular value for frequency to avoid errors
PlotFrequency(iii)=iii*.1; %array value for plotting frequency
simout3(iii)=sim("Complete_System_1.slx"); %Creating simulation variable 1x100 where each index...
simout4(iii)=sim("Complete_System_2.slx"); %is a simulation variable 1x1. This avoids numerical errors.
for ii=1:1:100 %Setting a loop to find max displacement
SystemMag(ii)=(max(simout3(ii).Displacement)); % Only Max displacement versus frequency not scaled.
SystemMag2(ii)=(max(simout4(ii).MRDisplacement));% Had to be indexed due to variable dimension
Paul le 5 Août 2023
It sounds like you've solved the immediate problem.
Based on what's been stated, the "vectorized" approach is taking advantage of a Simulink feature called Scalar Expansion. However, not all blocks support scalar expansion. If you update the model to use a block that does not support scalar expansion, like a Transfer Fcn block, you'll have to go to the loop method.