How to set a parameter as a variable in a simulink block from Matlab?
Show older comments
Hello everyone,
I am using a function in matlab that has as input a frequency. The idea is that the function modifies the cutoff frequency of a low pass filter (from a Simulink model) with the frequency provided as input. The Simulink model splits a time function in two new functions (one with frequencies below the cutoff frequency and the other with the frequencies higher than the cutoff frequency). The code from the second line to the fifth one, is meant to update the function that is going to be split (in case it has been modified)
So far I have come up with the following code:
function Create_Signal_PuissancekW(x)
load puissance_kW
puissance_kWx=transpose(puissance_kW);
time=1:length(puissance_kW);
signalbuilder('Division_Profil_Charge/ProfilCharge', 'set', 'Puissance', 'Group_1', time, puissance_kWx)
set_param('Division_Profil_Charge/Pass Bass','Wlo','x')
sim('Division_Profil_Charge','SimulationMode','normal');
The problem I have is that the function set_param() doesn't allow me to put a variable instead of a real value. I have tried with set_param(gcb, 'UserData', x) and even puting sim('Division_Profil_Charge','SimulationMode','normal','Pass Bass/Wlo',x) but none of them seems to work. Does anyone have an idea of what the problem might be?
Here is the Simulink model, in case it is necessary:

And this is the error displayed by Matlab when I try to run the function: Create_Signal_PuissancekW(0.00175)

Thanks a lot in advance!
Accepted Answer
More Answers (1)
Dev Club
on 22 Jul 2019
0 votes
Hello Sebastian! I would like to know can I set the one of the parameters of 4 pulse generators in my circuit below simultaneously by one single input variable?
eg. I have a constant block (0.9) on left side (which is duty cycle) which goes into code block, can you suggest any code which will set a particular parameter of pg1 (Pulse Generator) and rest of them simultaneously?
And if code can be written what will be at the output of code block?
Thanks!

Categories
Find more on Event Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!