How to set a parameter Max to a value from another parameter

2 次查看(过去 30 天)
I have a constant parameter that is added to the datadictionary and must be between 1 and the value of another parameter in the data dictionary. I can set the size of parameters using this value by putting it in single quotes but the max property does not seem to allow you to do this. It doesn't even work if the datatype of the referenced variable is changed to double.
Max = 8 works
Max = double(2.3) works
Max = 'My_Ref_Variable' doesn't work.
Max = My_Ref_Variable.Value gets the correct value but doesn't preserve the equation.
Max = '=My_Ref_Variable.Value' Doesn't work.
How can I preserve Max = My_Ref_Variable.Value so that it is evaluated at build time.

回答(1 个)

Ayush
Ayush 2023-9-27
Hey Reuben,
I understand that you are setting a constant parameter in a data dictionary, with its value dependent on another parameter. You are facing challenge in preserving the equation Max = My_Ref_Variable.Value and have it evaluated at build time to ensure the correct value is assigned.
To preserve the equation Max = My_Ref_Variable.Value and have it evaluated at build time, you can use a different approach. Instead of directly assigning the value to Max, you can use a lambda function or a function handle to dynamically evaluate the value of My_Ref_Variable.Value during runtime. Here's how you can achieve this using MATLAB :
% Define a function handle to evaluate the value at build time
getMaxValue = @() My_Ref_Variable.Value;
% Assign the function handle to Max
Max = getMaxValue();
By creating a lambda function or function handle that references the desired parameter (My_Ref_Variable.Value), the value can be dynamically evaluated whenever needed during the build process, ensuring it is up-to-date. This allows the equation to be preserved and the maximum value to be correctly assigned based on the evaluated value of My_Ref_Variable.
To learn more about function handle or lambda function , please refer to the MathWorks documentation link below :
Hope this helps !
Regards,
Ayush Goyal

类别

Help CenterFile Exchange 中查找有关 Parrot Minidrones 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by