Not able to change the values of the voltage source on Simulink

5 ビュー (過去 30 日間)
Rosheen Hassan
Rosheen Hassan 2022 年 11 月 27 日
回答済み: Sameer Pujari 2022 年 11 月 30 日
I've modelled a buck converter on simulink and wish to change the values of the voltage source using set_param in the m file. I created a vector that contains the values of Vin I want my buck to run on (min was 1 and max was 300V) and set a for loop to iterate 200 times as below
for i = 1:200
set_param('bs/DC_V', 'Amplitude', num2str(Voltage_IN(i)));
end
When I run the simulation my voltage source stays constant on 300, the last value in my vector and doesnt vary from 1 to 300 as I wanted. Can someone explain why this is so and what am I doing wrong?

採用された回答

Sameer Pujari
Sameer Pujari 2022 年 11 月 30 日
Hi Rosheen
I understand that you want to change the value of a certain block parameter and then simulate the model for that certain value
In your code snippet, the for loop is setting the value of the parameter as per the array but is not simulating the model for the certain value. Hence at the end you could only see the last value in the array
You can use the following way to set the parameter and simulate the model.
Voltage_IN=linspace(1,300,200);
for i = 1:200
%Creates SimulationInput objects to make changes to model for multiple or individual simulation
in(i)=Simulink.SimulationInput('vdp');
%Set a certain Gain values for each Simulation input
in(i)= in(i).setBlockParameter('vdp/Mu', 'Gain', num2str(Voltage_IN(i)));
end
% Simulate a model with the sim function by using the specified techniques to specify parameter values.
out= sim(in,'ShowSimulationManager','on','ShowProgress','on')
% Logged signals during the simulation can be viewed
plot(out)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSwitches and Breakers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by