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

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)

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

but can I use the result function in such a way here also,maybe I understand; my question is can I use all( ismember( result[1,2,3]) or maybe instead of result use value..? Is the list also in appdesigner programmed with numbers that you can refer to as the result corresoonds to?
What is the output of this 'value' that is generated by the callback function; is it some numbers or names of salts chosen..?
I think the easiest thing for you to do is create a simple app with a list and play around with it.
Value is a text value corresponding to the selected item in the list. If you have 3 items in a list of Red, Yellow, and Blue, and select the 2nd item, Value='Yellow'. I'm not exactly sure how your code compares your list box, but perhaps it would be this in the app (untested)?
if(all(ismember(app.value,app.ChooseminimumtwosaltsandmaximumthreesaltsListBox.Items(1:3))))
I suppose you could use a lstdlg, but that will open a separate dialog window. Just incorporate the list into your app canvas.
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

Asked:

on 8 Apr 2023

Edited:

on 8 Apr 2023

Community Treasure Hunt

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

Start Hunting!