How to use result of a list in matlab app designer?
조회 수: 17 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!