Writing in a listbox

조회 수: 1 (최근 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 CenterFile Exchange에서 Scripts에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by