loading items from listbox1 to listbox2

조회 수: 19 (최근 30일)
Sm tg
Sm tg 2014년 5월 13일
댓글: Sm tg 2014년 5월 16일
I am having 2 listboxes. listbox 1 contains a list of files. I want to select multiple files from listbox1 and want to list them in listbox2. as i double click on any file on listbox1 it should get listed in listbox2.
My problem is..
when i double click a item in listbox1, it gets listed in listbox2. but when i double click the second item in listbox1, in listbox2, it comes in place of the previous item, not as the second item in the list.
i want to list all the items in listbox2 when double clicked from listbox1.
here is what , i am trying
function listbox1_Callback(hObject, eventdata, handles)
get(handles.figure1,'SelectionType'); % If double click if strcmp(get(handles.figure1,'SelectionType'),'open') index_selected = get(handles.listbox1,'Value'); file_list = cellstr(get(handles.listbox1,'String')); % Item selected in list box filename = file_list{index_selected};
set(handles.listbox2,'String',filename)
end
Thank you for suggestions..
  댓글 수: 1
Sm tg
Sm tg 2014년 5월 16일
now I am facing problem with loading a file from listbox2. I want to select all items (.mat files) in listbox 2 as I press a pushbutton and tabulate their variables in guitable.
here is my code:
listn = cellstr(get(handles.listbox2,'String'));
for i=1:length(listn)
filen=listn{i};
Pathn=get(handles.path_1,'String');
tbldata(i)=load(fullfile(Pathn,filen));
tblval(i,:)={filen,tbldata(1,i).var1,tbldata(1,i).var2,tbldata(1,i).var3};
end
set(handles.datatable,'data',tblval);
it is giving error with "load fullfile". it is not getting the items (.mat file) in 'filen'.
Please help me.

댓글을 달려면 로그인하십시오.

채택된 답변

Sara
Sara 2014년 5월 13일
Add this:
temp = get(handles.listbox2,'String');
temp{end+1} = filename;
set(handles.listbox2,'String',temp)
  댓글 수: 1
Sm tg
Sm tg 2014년 5월 16일
thank you for your answer..
I can now do it in this way also..
if strcmp(get(handles.figure1,'SelectionType'),'open') index_selected = get(handles.listbox1,'Value'); file_list = cellstr(get(handles.listbox1,'String')); % Item selected in list box
filename1 = file_list{index_selected};
end
update_listbox2 = cellstr(get(handles.listbox2, 'String')); newmenu =[filename1;update_listbox2]; set(handles.listbox2,'String', newmenu);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by