图像缩略图

天然订单文件名排序

版本3.4.4(24.4 kb) Stephen23
具有可自定义数字格式的字母数字为文件名或档案。

20.4k下载

更新2022年1月31日

查看许可证

编者注:该文件被选为Matlab Central选择一周

排序字符串/单元格数的元素使用 纳特斯特
对字符串/单元格数的行进行排序 Natsortrows
概括
字母数字在字符串/单元/结构数组中对文本进行排序。考虑到任何数字substring的值,按字符代码对文本进行分类。例如:
>> a = {'a2.txt',,,,'a10.txt',,,,'a1.txt'};
>>排序(a)
ans ='a1.txt''a10.txt''a2.txt'
>> natsortfiles(a)
ans ='a1.txt''a2.txt''a10.txt'
默认 Natsortfiles 将所有连续数字解释为整数数字,可以使用正则表达式指定数字substring识别:请参阅 纳特斯特 有关详细信息。
Natsortfiles 不执行幼稚的天然顺序排序,而是分别对文件名和文件扩展进行分类以确保字典排序,在该字典中,较短的文件名总是在更长的情况下进行排序。同样,在每个文件分离器字符上分配了文件pat径,并且文件层次结构的每个级别都会单独排序。
dir()的示例
p ='c:\ ymedir \ subdir';
s = dir(fullfile(p,'*。文本');
s = natsortfiles(s);
为了k = 1:numel(s)
f = fullfile(p,s(k).name)
结尾
文件依赖性
自然顺序由功能提供 纳特斯特 (文件交换34464)。所有的 纳特斯特 可选输入由金宝app Natsortfiles
例子
>> a = {'a2.txt',,,,'a10.txt',,,,'a1.txt'}
>>排序(a)
ans ='a1.txt''a10.txt''a2.txt'
>> natsortfiles(a)
ans ='a1.txt''a2.txt''a10.txt'
>> b = {'test2.m';'test10 gold.m';'test.m';'test10.m';'test1.m'};
>>排序(b)%错误的数字订单:
ans =
'test.m'
'test1.m'
'test10 gold.m'
'test10.m'
'test2.m'
>> natsortfiles(b)更短的名称之前:
ans =
'test.m'
'test1.m'
'test2.m'
'test10.m'
'test10 gold.m'
%%目录名称:
>> c = {'a2-over \ test.m';'a10 \ test.m';'a2 \ test.m';'a1 \ test.m';'a1-archive.zip'};
>>排序(c)%错误的数字顺序,“ - ”之前的“ \”:
ans =
'a1-archive.zip'
'a10 \ test.m'
'a1 \ test.m'
'a2-over \ test.m'
'a2 \ test.m'
>> natsortfiles(c)更短的名称之前:
ans =
'a1 \ test.m'
'a1-archive.zip'
'a2 \ test.m'
'a2-over \ test.m'
'a10 \ test.m'
>> d = {'a1 \ b',,,,'a+/b',,,,'A/B1',,,,'a =/b',,,,'a \ b0'};
>>排序(D)
ans ='a+/b''A/B1''a1 \ b''a =/b''a \ b0'
>> natsortfiles(d)
ans ='a \ b0''A/B1''a1 \ b''a+/b''a =/b'
>> f = {'test_new.m';'test old.m';'test.m'};
>>排序(f)%注释' - ' - '之前的'。':
ans =
'test old.m'
'test.m'
'test_new.m'
>> natsortfiles(f)更短的名称之前:
ans =
'test.m'
'test old.m'
'test_new.m'

引用为

Stephen23(2022)。天然订单文件名排序(//www.tatmou.com/matlabcentral/fileexchange/47434-natural-rord-filename-sort),matlab中央文件交换。检索

MATLAB释放兼容性
使用R2010B创建
与R2009B兼容,后来发布
平台兼容性
视窗 苹果系统 Linux

社区寻宝

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

开始狩猎!