How define drop down elements based on previous input in Live Editor?

40 ビュー (過去 30 日間)
Luis Lopez
Luis Lopez 2021 年 7 月 21 日
編集済み: Prateek Rai 2021 年 9 月 15 日
Hi,
I'm working with Live Editor trying to use Drop Down in Control elements. What I want to do is include a defined list of elements in "Engine List" if my variable Customer is "Red Bull" and a different list of elements in "Engine List" if my first input was "Ferrari or McLaren". I couldn't include my Live Script code, sorry. I'm using Matlab 2018A.
Thanks for your support
% Select your Customer in the list
%
Customer = 'Red Bull';% or 'Ferrari' or 'McLaren' in this list of elements
% Choose yor Engine
Engine = 'America';% 'Europe', 'Asia', Europe only available for "Ferrari" and Asia only for "McLaren"

回答 (1 件)

Prateek Rai
Prateek Rai 2021 年 9 月 14 日
編集済み: Prateek Rai 2021 年 9 月 15 日
To my understanding, you want to create dynamic dropdown whose list items can depend on the value of other variable(or selection).
From R2021a, you can create dynamic controls in live scripts by linking variables to drop-down items. To populate the items in the drop-down list using values stored in a variable, in the Items > Variable field, select a workspace variable. The variable must be a string array to appear in the list.
So a possible workaround could be:
First Section contains:
% Select your Customer in the list
% Here "Customer" has a dropdown with 'Red Bull' , 'Ferrari', and 'McLaren' as dropdown list
Customer = 'Red Bull';% or 'Ferrari' or 'McLaren' in this list of elements
p = ["America", "Europe", "Asia"];
if strcmp(Customer,'Ferrari')
p = ["America", "Europe"];
elseif strcmp(Customer,'McLaren')
p = ["America", "Asia"];
end
%p will be string array whose value depends on the selection of Customer Dropdown
After running this section you will get the variable 'p' in your workspace.
Now, the next section should contain:
Engine = % Dropdown with 'p' as linked Variable
% Note: For linking variable 'p', Go to items --> Variable field, and select variable p
Now when you choose the' Customer' value in the dropdown, it will affect the variable 'p' and hence items in the dropdown list of 'Engine' will also change accordingly.
Please refer to Add Interactive Controls to a Live Script MathWorks documentation page to find more on adding interactive controls to a live script.

カテゴリ

Help Center および File ExchangeSimulink Environment Customization についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by