On this earlier publish, I used to be tuning the worth of a Achieve block. This week I obtained the query: Can I do the identical for a parameter of sort popup?
The Downside
in(1:3) = Simulink.SimulationInput(mdl);
in(i) = in(i).setModelParameter(SimulationMode=‘Fast’);
in(i) = in(i).setModelParameter(RapidAcceleratorUpToDateCheck=‘off’);
in(1) = in(1).setBlockParameter(blk,‘selection’,‘Random’);
finish
The Answer
classdef noise < Simulink.Masks.EnumerationBase
enumeration
Random (1,‘Random’)
Pulse (2,‘Pulse’)
Sequence (3,‘Sequence’)
finish
finish
Within the Subsystem underneath the masks, I would like to switch how the variable is specified within the block dialog. For this instance, as a substitute of utilizing the variable selection straight, I must specify noiseValues(selection). The documentation explains the syntax, however in brief you start with the enumeration title (noise on this instance) and also you append “Values” to it. You then cross to it, between parenthesis, the popup variable (selection on this instance):
For those who create the masked Subsystem that method, you’ll discover that the dialog has a brand new “Affiliate Variable” choice:
It will open a dialog to specify the variable and optionally create it if it doesn’t exist. For this instance, I’ll create it myself:
noiseType = noise.Random;
When you click on okay, within the block dialog, you will note the variable title and the enumeration sort subsequent to it:
And that is it, now it is time to simulate the mannequin:
mdl = ‘testNoiseTunable’;
in(1:3) = Simulink.SimulationInput(mdl);
in(i) = in(i).setModelParameter(SimulationMode=‘Fast’);
in(i) = in(i).setModelParameter(RapidAcceleratorUpToDateCheck=‘off’);
in(1) = in(1).setVariable(‘noiseType’,noise.Random);
in(2) = in(2).setVariable(‘noiseType’,noise.Pulse);
in(3) = in(3).setVariable(‘noiseType’,noise.Sequence);
out = sim(in,‘ShowProgress’,‘off’);
As soon as the simulation completes, we are able to plot the outcomes and ensure that the parameter has been tuned:
plot(out(1).yout{1}.Values);
plot(out(2).yout{1}.Values);
plot(out(3).yout{1}.Values);
legend({‘Random’,‘Pulse’,‘Sequence’});
Now it is your flip