Listbox content from structure hierarchy (GUIDE)
3 views (last 30 days)
Show older comments
I have a listbox in which one I would like to set as content the subfield names of a structure.
Example: 'Database' is the structure which have inside the fieldnames Car, Bus and Motorbike. These fieldnames are 1x1 struct (e.g Database.Car) and are used as subfields.
Then I want to create a listbox which contains the subfields and mantain this listbox updated since different subfields will be added.
Thanks in advance,
0 Comments
Accepted Answer
Jan
on 31 Jul 2013
Here "Car" etc are the "fields", not the "subfields" (which would mean something like: DataBase.Vehicle.Car).
DataBase.Car = 1;
DataBase.Bus = 2;
DataBase.Motorbike = 3;
List = fieldnames(DataBase);
uicontrol('Style', 'listbox', 'String', List);
Keeping the listbox "updated" when the struct is changed, is very complicated. You need an object oriented approach to start a callback, when the data are changed. But you can fake it by not adding further fields manually, but when you use a dedicated function for this:
function S = myAddField(S, Field, Data)
S.(Field) = Data;
updateGui(S); % <-- Implementation depends on your GUI
3 Comments
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!