Matlab gui List box problem

I have two list boxes. In first list box i have listed 5 items. Now i have a select button to select item. The selected item should list in second list box. Pls help me out of this. Thanks

回答 (1 件)

Arthur
Arthur 2012 年 11 月 9 日
編集済み: Arthur 2012 年 11 月 9 日

2 投票

Something like this sould work:
val = get(handles.listbox1,'Value'); %get selected item
str = get(handles.listbox1,'String'); %get content
set(handles.listbox2,'String',str{val}); %put item in 2nd listbox
or, to add the item to existing items in listbox2:
val = get(handles.listbox1,'Value'); %get selected item
str1 = get(handles.listbox1,'String'); %get content
str2 = get(handles.listbox2,'String')); %get content of listbox 2
set(handles.listbox2,'String',[str2 str1{val}]); %put item in 2nd listbox

1 件のコメント

Josef Rozinek
Josef Rozinek 2013 年 9 月 26 日
Hi, this worked for me nicely, however I found one weird thing I don't understand(maybe someone could enlighten me :-D). The above works, but only for one selection in the first listbox. For more selections I get the following error:
Error using set Invalid parameter/value pair arguments
The solution for me was to replace curly braces in selected_str{selected_val} with parentheses and then it works fine even for more selections.
Cheers
Josef

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

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

質問済み:

2012 年 11 月 9 日

コメント済み:

2013 年 9 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by