Populate Listbox with exceptions

조회 수: 1 (최근 30일)
Robert Worm
Robert Worm 2018년 8월 21일
편집: Jan 2018년 8월 23일
Currently my method of outputing directory files to a listbox is:
dir_struct = dir(pwd)
[sorted_names,sorted_index] = sortrows({dir_struct.name}');
handles.file_names = sorted_names;
set(handles.files,'String',handles.file_names,'Value',1)
When getting the sorted_names I want to exclude certain files. Let's say files containing 'include' should be included, /w 'exclude' not.
I was thinking about using regexp. Suggestions?
  댓글 수: 1
Robert Worm
Robert Worm 2018년 8월 23일
Just giving this a push.

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

채택된 답변

Jan
Jan 2018년 8월 23일
편집: Jan 2018년 8월 23일
Replace
[sorted_names,sorted_index] = sortrows({dir_struct.name}');
by the simpler:
sorted_names = sort({dir_struct.name});
Now you want to exlucde names, which contain the substring 'exclude'?
sorted_names(contains(sorted_names, 'exclude')) = [];
Or include files, whose name contains 'include':
sorted_names = sorted_names(contains(sorted_names, 'include'));
With older Matlab versions before contains was available, use:
function T = myContains(Str, Key)
T = ~cellfun('isempty', strfind(Str, Key));
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by