Callback_listbox1 event to change content of another listbox2

2 views (last 30 days)
Manuel on 7 Aug 2013
I have a listbox1 with different items and when one of these items is selected (e.g project1) this item is used as a field structure name. Therefore the listbox2 is updated with the fieldnames of 'Database.project1', and example is shown below.
function listbox1_Callback(hObject, eventdata, handles)
project1 = get(hObject)%%takes selection item
load('Database.mat');%load Database structure
List = fieldnames(Database.(project1));%take fieldnames from Database.project1 structure
set(hObject.listbox2,'String',List);% update new items for listbox2
But this code is giving the next error:
Argument to dynamic structure reference must evaluate to a valid field name.
Any idea about how can be implemented?
Thanks in advance

Accepted Answer

Jan on 7 Aug 2013
project1 = get(hObject)
seems to be incomplete. Do you mean:
string = get(hObject, 'String');
value = get(hObject, 'Value');
project1 = string{value};
Manuel on 9 Aug 2013
Problem solve, just need to refer to the content of the variable by using ().
List2 = fieldnames(Database.(project1));

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by