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

12 views (last 30 days)
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.

Answers (1)

Cris LaPierre
Cris LaPierre on 8 Apr 2023
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 Comments
Muazma Ali
Muazma Ali on 8 Apr 2023
thanks , I am now making a small app to play with the list as you suggested:)

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer 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!