ordering a listbox by extension
이전 댓글 표시
Is it possible to load two types of files into a list box BUT order not by filename but with the same extensions.
I use this, but it appears to order by date. I would like to group the two sets of files together so If I am only loading *.jpg and *.xls, I need all the jpgs ordered first, and then all the xls.
for Index = 1:length(ImageFiles)
baseFileName = ImageFiles(Index).name;
[folder1, name, extension] = fileparts(baseFileName);
extension = upper(extension);
ListOfImageNames = [ListOfImageNames baseFileName];
end
set(handles.listbox1, 'string', ListOfImageNames);
답변 (1개)
Joseph Cheng
2014년 12월 8일
two ways to accomplish this, stack the extensions as well and use sort/sortrows to order the extensions. with the sorting functions you can get the reordering index and apply that to your list of files.
second method would be how you're creating your list of files. are you using dir()? if so you can use the wildcard filter in it to compile 2 lists.
ImageFiles=dir('yourFolder\*.jpg'); %to get the list of jpegs
XLSfiles=dir('yourfolder\*.xls'); %to get the list of xls files
set(handles.listbox1,'string',[ImageFiles;XLSfiles]);
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!