App Designer: populate list box with string from excel file then compare user input with excel to populate "next" list box?
Mostra commenti meno recenti
Dear MATLAB users,
I am attempting to create an app with App Designer (2019a) which does the following:
- Loads an Excel file (text/string data only) with user file selection
- Populates ListBox1 with first row of Excel file
- Uses the value selected by the user from ListBox1 to populate ListBox2 with options listed "below"/in rows below option selection (from Excel sheet).
- This selection continues until all options from the first row have been used.
A simplified example of my Excel sheet is as follows:

I have successfully loaded the excel sheet and populated ListBox1 (albeit I believe inefficiently). But cannot get "strcmp" to return a "1" for the row where the value selected appears in the Excel sheet. Furthermore, if I try to make my Excel data when converted to a cell array ("O") as a global variable ("app.O") the population of my first ListBox does not work. My call backs for the "LoadExcelTemplate" pushbutton and ListBox1 are as follows:
% Button pushed function: LoadExcelTemplateButton
function getexcelfile(app, event)
[file,path]=uigetfile('../*.xlsx');
app.OPS=readtable(file,'ReadVariableNames',0,'TextType','string','TreatAsEmpty',{''})
numOPS=width(app.OPS)
set(app.ListBox1,'Enable','on')
for i=1:numOPS
O{i}=app.OPS(:,i);
app.ListBox1.Items(i)=cellstr(O{i}{1,1})
end
end
% Value changed function: ListBox1
function list1items(app, event)
OP1 = app.ListBox1.Value;
numOPS=width(app.OPS);
for i=1:numOPS
O{i}=app.OPS(1,i);
end
x=strcmp(O,OP1);
end
3 Commenti
Jesus Sanchez
il 8 Dic 2019
Did you check the value of O and OP1 when evaluating the strcmp with the debugger? If so, did it fail even if both had the same value?
hollyhue
il 9 Dic 2019
Jesus Sanchez
il 9 Dic 2019
I am happy for you! If you would, please post your solution as an answer and accept it when possible (I think its a delay of 24 hours for self-answers). This way, if someone has the same problem one day they will have a possible solution avaliable :)
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Data Import from MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!