Sunday, November 3, 2024
HomeMatlabLearn how to Create a Masks Popup Parameter that may be tuned...

Learn how to Create a Masks Popup Parameter that may be tuned in Fast Accelerator » Man on Simulink


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

I’ve this mannequin with a masked subsystem that has a popup parameter. Underneath the masks, the variable related to the popup, selection, is used to manage what sort of noise is added to the sign:
If I attempt to simulate the mannequin as described within the earlier weblog publish, I get an error saying that it is not attainable to make use of setBlockParameters and RapidAcceleratorUpToDateCheck=’off’ on the identical time:

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

The very first thing it is advisable to do is affiliate an enumeration with the popup parameter. For this instance, the enumeration is:

classdef noise < Simulink.Masks.EnumerationBase

enumeration

Random (1,‘Random’)

Pulse (2,‘Pulse’)

Sequence (3,‘Sequence’)

finish

finish

I then affiliate it with the parameter within the Masks Editor by double-clicking on the Sort choices discipline:

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

If you’re creating masked library blocks with parameters of sort popups, be good to your customers and affiliate the popup with an enumeration sort. It will allow them to tune it in Fast Accelerator optimally. This may even allow the parameter to be tuned if the mannequin is deployed with Simulink Compiler.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments