Issues with SImulink Output to a Vector.

9 vues (au cours des 30 derniers jours)
Kirby Rainer
Kirby Rainer le 3 Août 2023
Réponse apportée : Paul le 5 Août 2023
Hello All,
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
  2 commentaires
Paul le 3 Août 2023
Hi Kirby,
To try to get to the bottom of this, suggest starting with ...
Run this code
With MR Damper not activated
1) Go to Simulink and click Debug -> Information Overlays -> Signal Dimensions.
2) Click on Update Model
3) Post a screen capture of the model after the update.
4) Activate the MR Damper
5) Click on Update Model
6) If the signal dimensions on any of the lines change, post another screen capture.
What's inside the MR Damper block?
Kirby Rainer
Kirby Rainer le 5 Août 2023
Thank you I appreciate it. I was unaware of the method you described to check signal dimensions. The problem was due to a multiplicaiton block set to matrix multiplication. With matrix multiplication the output was 100 *(1x100) and it was adding a single constant to all my results. With a single constant for DriveForceFrequency it did not have any issues. The working code I originally sent would send and store simulation output 1 constant at a time.
Changing the block to elementwise the vectorized code now works.
I am posting the error in a image and the MR damper. It is a simple Bingham Model of a MR Damper with Derivative control. I had to start here before moving on to more sophisticated models of MR Dampers.

Connectez-vous pour commenter.

Réponse acceptée

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.

Plus de réponses (0)


En savoir plus sur General Applications dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by