Populate Listbox with exceptions
1 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!