Writing in a listbox

8 ビュー (過去 30 日間)
JA
JA 2016 年 8 月 4 日
コメント済み: JA 2016 年 8 月 4 日
I am trying to write a list in a listbox.
code:
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
error = getappdata(0, 'error_norm');
rows = size(error,1);
for i = 1:rows
set(handles.listbox1,'string',strcat('filt_',num2str(i)));
for j = 1:length(error)
set(handles.listbox1,'string',strcat('sig_',num2str(i),'_',num2str(j)));
for k = 1:length(error{j}.main)
set(handles.listbox1,'string',strcat('seg_',num2str(i),'_',num2str(j),'_',num2str(k)));
end
end
end
where 'error' is a array of structure . i want to write on list box something like this:
filt_1
sig_1_1
seg_1_1_1
seg_1_1_2
sig_1_2
seg_1_2_1
seg_1_2_2
but apparently, 'set' function overwrites, so all i am getting is only 1 element and the last element.
How do i make it write all of it, any help will be appreciated.

採用された回答

Walter Roberson
Walter Roberson 2016 年 8 月 4 日
You need to create a cell array of strings first, and then set() that cell array as the String property of the handle.
  9 件のコメント
Walter Roberson
Walter Roberson 2016 年 8 月 4 日
all_choices = get(hObject, 'String');
choice_idx = get(hObject, 'Value');
chosen_string = all_choices{choice_idx};
JA
JA 2016 年 8 月 4 日
You are my savior today.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScripts についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by