Callback_listbox1 event to change content of another listbox2

1 回表示 (過去 30 日間)
Manuel
Manuel 2013 年 8 月 7 日
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
  1 件のコメント
Jan
Jan 2013 年 8 月 7 日
And in which line does the error occur?

サインインしてコメントする。

採用された回答

Jan
Jan 2013 年 8 月 7 日
project1 = get(hObject)
seems to be incomplete. Do you mean:
string = get(hObject, 'String');
value = get(hObject, 'Value');
project1 = string{value};
  2 件のコメント
Manuel
Manuel 2013 年 8 月 8 日
Now it detects perfectly the item selected, thanks a lot.
But when is going to check the fieldnames:
List2 = fieldnames(Database.project1);
I got the next error for this line:
Reference to non-existent field 'project1'.
I think is because is not taken the content of the variable project1 or also could be because project1 is a string and we are making reference to a cell, right? How could I solve that?
Manuel
Manuel 2013 年 8 月 9 日
Problem solve, just need to refer to the content of the variable by using ().
List2 = fieldnames(Database.(project1));

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by