Running Simulink Simscape model with a vector from MATLAB script as values
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Aharon Renick
le 14 Juin 2023
Modifié(e) : Manoj Mirge
le 17 Août 2023
Hello,
I am running the following MATLAB scipt, which calls a Simulink model:
N = 1000; % Perform N iterations
for i = 1:1:N
Res = 2 + 0.5*rand; % Res between 2 and 2.5 %[Ohm]
out = sim('motor_model','simulationmode','normal');
Mes = stepinfo(out.RotationSpeed, out.tout); % Step responce to input voltage
SimSteadySpeed(i) = Mes.SettlingMax;
SimSettleTime(i) = Mes.SettlingTime;
end
The simulink model represents a simple DC motor using simscape components:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1410129/image.png)
The value of the resistance in 'Resistor' is defined as Res, so each time the simulink simulation is called it defines a different value to resistance:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1410134/image.png)
Unfortinitly, this method is Very time consuming. I tried using 'Accelerator' and 'Rapid-Accelerator' modes, but they seem to take even longer overall (I assume MATLAB is rebuilding them every run becuase of the change is Res)
I tried using parfor, but that just got my computer stuck while 'loading the pool' or somthing like that.
Any ideas how i can run this more efficiently?
Thanks!
0 commentaires
Réponse acceptée
Manoj Mirge
le 17 Août 2023
Modifié(e) : Manoj Mirge
le 17 Août 2023
The workflow mentioned can also be achieved by the parameter sweeping of the model. The parameter sweeping includes changing the block parameter values between simulation runs and comparing and analyzing the output signal data from each run.
Please refer to the below attached link to read more about the parameter sweeping:
The parameter sweeping can be optimized by running multiple simulations in parallel. This can be achieved using the “parsim” command.
Please refer to the below attached link to read more about “parsim” and how to achieve the faster parameter sweeping using “parsim”:
Hope this helps.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Troubleshooting 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!