MATLAB: App Designer: populate list box with string from excel file then compare user input with excel to populate “next” list box

app designerexcelguistrcmp

Dear MATLAB users,
I am attempting to create an app with App Designer (2019a) which does the following:
  1. Loads an Excel file (text/string data only) with user file selection
  2. Populates ListBox1 with first row of Excel file
  3. Uses the value selected by the user from ListBox1 to populate ListBox2 with options listed "below"/in rows below option selection (from Excel sheet).
  4. This selection continues until all options from the first row have been used.
A simplified example of my Excel sheet is as follows:
sample_excel.JPG
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

Best Answer

I figured it out:
% Button pushed function: LoadButton
function getexcelfile(app, event)
[file,path]=uigetfile('../*.xlsx');
app.OPS=readtable(file,'ReadVariableNames',0,'TextType','string','TreatAsEmpty',{''})
app.numOPS=width(app.OPS)
set(app.ListBox1,'Enable','on','Visible','on')
set(app.Label,'Visible','on')
for i=1:app.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)
app.OP{1,1} = app.ListBox1.Value;
for i=1:app.numOPS
O{i}=app.OPS(:,i);
S(i)=cellstr(O{i}{1,1});
end
app.x(1,1)=find(strcmp(S,app.OP{1,1}))
numh=height(O{app.x(1,1)})-1;
for j=1:numh;
app.ListBox2.Items(j)=cellstr(O{app.x(1,1)}{j+1,1});
end
end