Writing in a listbox

4 views (last 30 days)
JA
JA on 4 Aug 2016
Commented: JA on 4 Aug 2016
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.

Accepted Answer

Walter Roberson
Walter Roberson on 4 Aug 2016
You need to create a cell array of strings first, and then set() that cell array as the String property of the handle.
  9 Comments
Walter Roberson
Walter Roberson on 4 Aug 2016
all_choices = get(hObject, 'String');
choice_idx = get(hObject, 'Value');
chosen_string = all_choices{choice_idx};
JA
JA on 4 Aug 2016
You are my savior today.

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!