Appdesigner: How do I include a cell-array of strings for "Items" of listbox through Appdesigner GUI?

14 次查看(过去 30 天)
Hello,
I am using Matlab 2018a Appdesigner to build an App. When I initialize the App, I read-in text from an Excel file using xlsread and save it as a public variable/property. I then try to have a Listbox later in the code use this cell-array of strings to populate the list. It seems to me that the Appdesigner GUI forces you to manually enter each Item as a string and will not allow you to provide a cell-array of strings as the Items. Am I missing something here? Please see code snippets below highlighting the area I'm struggling with:
...relevant snippets from Appdesigner code...
properties (Access = public)
Listbox_RPS_Names % This is the naming list for the RPS listbox on the Geometry Tab, 2a subtab
end
... skipping some lines...
% Code that executes after component creation
methods (Access = private)
% Code that executes after component creation
function GUI_ReadIn_Data(app)
GUI_Data = 'GUI_Data.xlsx';
[~,~,app.Listbox_RPS_Names] = xlsread(GUI_Data,'Specification_Information','B4:Y4');
end
end
... skipping down into the "Create UIFigure and components" section of the code...
% Create ListBox_RPS
app.ListBox_RPS = uilistbox(app.SelectRPSPanel);
app.ListBox_RPS.Items = {'app.Listbox_RPS_Names'};
app.ListBox_RPS.Position = [14 12 383 310];
app.ListBox_RPS.Value = {};
The issue is that Appdesigner forces the "app.ListBox_RPS.Items" to be a string when it should be a Cell-array...!?!? Please tell me I'm doing something silly here and missing a way to feed Appdesigner a Cell-array for these listboxes, as I have many of them that I would like to edit and update from a single file as opposed to in each individual listbox assignment.
Thanks for any insight on the matter and please let me know if you need more information about what I'm asking.
-Mike

采纳的回答

Freya H
Freya H 2018-10-24
One workaround would be to iterate through all entries such as:
for n = 1:size(app.Listbox_RP_names,1)
app.ListBox.Items{end+1} = app.Listbox_RP_names(n); %possibly {n} instead of (n)
end
This is not exactly an elegant way to do it, but that's how I managed to make it work before :)
Obviously this solution only works, if you want to add the entries to your listbox. If you want to overwrite you could either clear the listbox first or put the names into app.ListBox.Items{n}.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by