How to use result of a list in matlab app designer?

26 ビュー (過去 30 日間)
Muazma Ali
Muazma Ali 2023 年 4 月 8 日
編集済み: Cris LaPierre 2023 年 4 月 8 日
I am trying to convert my program to an app; I had earlier a list that looks like this when programmed:
S={'ZnBr2'; 'MgCl2'; 'CaCl2'; 'KCl'; 'MgBr2'; 'NaCl'; 'AlCl3'; 'CH3CO2K';'HCOOK';'HCOONa'; 'CaBr2'};
str={'Choose salts available, minimum of two and maximum of three'};
result=listdlg('Promptstring',str, 'ListSize', [400,400], 'ListString', S, 'SelectionMode', 'multiple');
And then I made a list in Matlab app designer so now I think I cant use the code above to make use of the list I made in my program earlier.
Actually I have different functions that supposed to run depended on which of the salts that are chosen from the list in app 3. So I don’t know how I can call the functions, earlier I called them with ‘result’ as the input. For instance I called a function like this before , in my program:
[best_salt_1, best_salt_2, samlet_vannaktivitet,vekt_prosent_best_salt_1,vekt_prosent_best_salt_2, error]=Amongst_CaCl2_MgCl2_ZnBr2(result);
Then the function starts with checking what the result included by investigating:
if all(ismember(result,[1 2 3 ]))
I am wondering whether the program I made before starting on the apps may be useful or is not because writing programs is not the same as making apps in Matlab.?
I am attaching the apps concerned, it is mainly app3.

回答 (1 件)

Cris LaPierre
Cris LaPierre 2023 年 4 月 8 日
In general, the way you program components in app designer is using callback functions. These are functions specific to a component, and they are run any time you interact with that component. Here, that would mean changing the item selected in the list.
When you change the selection, the Value property changes. You can use that to determine what item has been selected, and also use that in a conditional statement on what to do based on the selection.
When you add a callback function for this component (rt cilck > Callbacks > ValueChangedFcn), you will get a template that already extracts the Value property.
% Value changed function: ListBox
function ListBoxValueChanged(app, event)
value = app.ListBox.Value;
end
You can find some example apps here, though I don't see any that use listboxes.
  5 件のコメント
Cris LaPierre
Cris LaPierre 2023 年 4 月 8 日
Muazma Ali
Muazma Ali 2023 年 4 月 8 日
thanks , I am now making a small app to play with the list as you suggested:)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by