フィルターのクリア

Add items to listbox using push button and drop down menu

5 ビュー (過去 30 日間)
Matt
Matt 2017 年 7 月 4 日
編集済み: Adam 2017 年 7 月 4 日
I am creating a GUI using GUIDE in MATLAB2015. I have a drop down menu which the user selects a message to view, after that they click the Add push button to add the message name to a list box and display the data it contains in a table.
My problem is, if I want to add more than one message, instead of adding that message, it overwrites the previous one. Below is my current code:
addData = getappdata(handles.msgSel_menu, 'Data');
boxMsg = get(handles.msgSel_menu,'String');
boxMsgVal = get(handles.msgSel_menu,'Value');
set(handles.activeDataBox,'String',boxMsg{boxMsgVal});
set(handles.data_table, 'Data', addData);
Apologies if this has been done multiple times before, but as I'm relatively new to MATLAB I could do with a little explanation of any code that fixes my issue.
  5 件のコメント
Matt
Matt 2017 年 7 月 4 日
Sorry, I've now managed to add the different elements in, but they do not replace the initial string (e.g. 'Please Select...'), appear side by side and I am able to add more than one of the same message. Here is the code I currently have:
addData = getappdata(handles.msgSel_menu, 'Data');
boxMsg = get(handles.msgSel_menu,'String');
boxMsgVal = get(handles.msgSel_menu,'Value');
current_data = get(handles.activeDataBox, 'String');
new_data = [current_data, boxMsg{boxMsgVal}];
set(handles.activeDataBox,'String',new_data);
set(handles.data_table, 'Data', addData);
set(handles.activeDataBox, 'String', new_data);
Adam
Adam 2017 年 7 月 4 日
編集済み: Adam 2017 年 7 月 4 日
Well, there isn't any magic to creating a cell array - either you replace elements or concatenate with them.
If you want special rules to remove a certain string or not allow duplicates you would just have to program the logic in for that yourself when doing the concatenation.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by