How can I calculate a mask parameter based on another mask parameter?
11 views (last 30 days)
Show older comments
I am creating a mask for an electric load. I want the user to be able to specify the minimum voltage for the load. The mask asks the user to enter a value for the load's rated voltage in volts (Vrated) and a value for the minimum voltage as a percent (Vmin_p). I would like to have a third parameter for the minimum voltage in volts (Vmin) which is automatically calculated as Vrated * Vmin_p / 100.

For example, if Vrated is 120 and Vmin_p is 90, a third parameter (Vmin) should be created and calculated as 120 * 90 /100 or 108.
How should I go about this? Should I use set_param in the mask Code section?
0 Comments
Answers (1)
akshatsood
on 13 Sep 2023
Edited: akshatsood
on 14 Sep 2023
Hi Dajan,
I understand that you want to calculate a mask parameter based on another mask parameter. This can be achieved by leveraging the methods described in the Simulink.Mask class. To illustrate my approach, I have assumed a example model named sample_model that contains a subsystem with a mask applied to it
To clarify my approach, I utilized the Simulink.Mask.get method to extract the handle to the mask from the model. By using get_param, I retrieved the values of the mask parameters (Vrated and Vmin_p in your case). With these values, I calculated Vmin and leveraged the addParameter method to create the parameter and assign it the computed value.
Here is the code snippet that demonstrates the approach
path = 'sample_model/mask';
maskObj = Simulink.Mask.get(path); % get mask handle
param_one = get_param(path, 'value@Vrated'); % retrieve value for Vrated
param_two = get_param(path, 'value@Vmin_p'); % retrieve value for Vmin_p
Vmin = num2str((param_one * param_two)/100);
% create and add the mask parameter
maskObj.addParameter('Name', 'Minimum_Voltage', 'Prompt', 'Vmin', 'Value', Vmin);
Have a look at the below references for better understanding
I hope this helps.
3 Comments
akshatsood
on 14 Sep 2023
Edited: akshatsood
on 14 Sep 2023
To address the error you encountered, it appears that the incorrect path was specified for the Simulink.Mask.get method. I recommend creating the MATLAB script in the same location as your model and injecting the code into it.
To clarify on the path I have used in the code, I started by creating a blank model called 'sample_model'. Inside this model, I added a subsystem block named 'mask' and applied the mask to it. Please ensure that you have followed a similar approach for your model.
Also do change Minimum Voltage to Minimum_Voltage while using the addParameter method as the former is not a valid name.
See Also
Categories
Find more on Simulink Environment Customization 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!
