How To Insert Elements in Listbox - MATLAB Answers - MATLAB Central
How To Insert Elements in Listbox - MATLAB Answers - MATLAB Central
howtoinsertelementsinlistbox?
AskedbyUsamaJavedon26Jan2012
LatestactivityCommentedonbyhushpuppyon15May2015
AcceptedAnswerbyChandraKurniawan
568views(last30days)
howcaniinsertlistofimagesintolistbox??Ihaveafoldercontaingimagesandiwanttoinsertlistofimages
intothelistbox
0Comments
Tags
gui guide imageprocessing image
Products
Noproductsareassociatedwiththisquestion.
RelatedContent
4Answers
Vote
4
Link
AnswerbyChandraKurniawanon27Jan2012
Acceptedanswer
Hi,Usama.
Maybeyouareseekingforsomethinglikethis?
Intheopeningfcn
functionuntitled_OpeningFcn(hObject,eventdata,handles,varargin)
handles.output=hObject;
files=dir(fullfile(pwd,'Folder01','*.png'));
forx=1:length(files)
handles.images{x}=imread(fullfile(pwd,'Folder01',files(x).name));
end
set(handles.listbox1,'string',{files.name});
guidata(hObject,handles);
Inthelistbox1callback
functionlistbox1_Callback(hObject,eventdata,handles)
handles.output=hObject;
index=get(handles.listbox1,'value');
imshow(handles.images{index});
guidata(hObject,handles);
Youcanalsochangetheimageextentionbyreplacingpngwithanotherextention
Eq:files=dir(fullfile(pwd,'Folder01','*.jpg'))
AndifitisDICOMfiles
files=dir(fullfile(pwd,'Folder01','*.dcm'));
forx=1:length(files)
handles.images{x}=dicomread(fullfile(pwd,'Folder01',files(x).name));
end
Ihopethishelps.
8Comments
Show5oldercomments
hushpuppyon15May2015
hi@chandra,i'veusedthecodeprovidedabove..butimgettingthiserror:'Cellcontentsassignment
toanoncellarrayobject'.Canyoutellmewhatwentwrong?AllIgetisablanklistbox.
ImageAnalyston15May2015
Try
fork=1:length(files)
listboxItems{k}=files(k).name;
end
set(handles.listbox1,'String',listboxItems);
hushpuppyon15May2015
@imageanalyst,i'vetriedyourcode..thiscodeseemtodisplayallmyfilenamesnow..buttheimage
isnotappearingonmyhandles.imageswhenIclickonit..
Vote
4
Link
AnswerbyChandraKurniawanon27Jan2012
Inopeningfcn
functionuntitled_OpeningFcn(hObject,eventdata,handles,varargin)
handles.output=hObject;
handles.cdir=pwd;
set(handles.listbox1,'enable','off');
guidata(hObject,handles);
Inpushbuttoncallback
functionpushbutton1_Callback(hObject,eventdata,handles)
handles.output=hObject;
fn=uigetdir(handles.cdir,'Selectdirectory');
iffn~=0
handles.cdir=fn;
img=dir(fullfile(handles.cdir,'*.png'));
forx=1:length(img)
handles.I{x}=imread(fullfile(handles.cdir,img(x).name));
end
iflength(img)~=0,set(handles.listbox1,'enable','on');
else,set(handles.listbox1,'enable','off');
end
set(handles.edit1,'string',handles.cdir);
set(handles.listbox1,'string',{img.name});
end
guidata(hObject,handles);
Inlistboxcallback
functionlistbox1_Callback(hObject,eventdata,handles)
handles.output=hObject;
index=get(handles.listbox1,'value');
imshow(handles.I{index});
guidata(hObject,handles);
MATLABAnswers
7Comments
Show4oldercomments
ElysiCochinon24Oct2012
siriwantedonemorelistboxinmyGUI...thesamecodewhenwritten...listbox1'simage1isshowing
listbox2'simage...butlistbox2'simagesarebeingdisplayedcorrectly...canurectifymyerror....same
wayiwantedtoswapthecontentsof2listboxes....andalsoiwantedsamecontentsoflistbox1in
listbox2....pleasedoreplyme.....
WalterRobersonon24Oct2012
PleasestartanewQuestionforthis,andshowyourcodeinthatnewQuestion.
ElysiCochinon31Jan2013
hi,chandra,onedoubt,inadditiontothelistboxandaxes....ihavetwobuttonsalso....onenamed
"DELETE"andtheothernamed"RESTORE".....
intheDELETEbuttonwheniselectaparticularitemfromlistboxthatnamegetsdeletedfromthe
listboxandthecorrespondingimagegetsdeletedfromthefolder....
onclickoftheRESTOREbuttonallthedeleteimagesshouldgetdisplayedinafigurefileandadded
backtothefolder.....
pleasecanuhelpmedothisoption.....
itried,itsworkingwhenonlyoneimageisdeleted.....ifideletemorethanoneitem,onlythelast
deleteditemisgettingrestored.....canuhelpmesortitout.....
MATLABAnswers
Vote
1
Link
AnswerbyImageAnalyston27Jan2012
Idon'tknowhowtoputimagesintolistboxes.Youcanputthenameoftheimagefilesintothelistboxes(like
Titusshowedyou)butyoucan'tputtheimagesthemselvesinwithMATLABonly.However,youcanputan
ActiveXcontrolontoyourGUI,andtherearethirdpartyActiveXcontrolsthatcanhaveimagesinalistbox,such
as(http://www.atalasoft.com/products/dotimage/winforms).OryoucanuseMicrosoft's"ListView"control:
http://msdn.microsoft.com/enus/library/ie/bb398790.aspx.Scrolldownthepageabouthalfwayuntilyouseethe
listboxwithpicturesofbicyclesinit.
0Comments
Vote
0
Link
AnswerbyTitusEdelhoferon26Jan2012
HiUsama,
somethinglikethefollowing:
files=dir(fullfile(theFolder,'*.jpg'));
set(handles.listbox1,'string',{files.name})
Titus
0Comments
MATLABAnswers
MATLABandSimulinkresourcesforArduino,LEGO,andRaspberryPi
Learnmore
DiscoverwhatMATLABcandoforyourcareer.
Opportunitiesforrecentengineeringgrads.
ApplyToday
MATLABAcademy
NewtoMATLAB?
LearnMATLABtoday!
19942016TheMathWorks,Inc.
MATLABAnswers