自然秩序文件名排序

版本3.4.4 (24.4 KB Stephen23
字母数字排序的文件名或文件路径,具有可自定义的数字格式。

22 k下载

更新2022年1月31日

查看许可协议

编者按:该文件被选为MATLAB中央本周精选

用于对字符串/单元格数组的元素进行排序 的作用
用于对字符串/单元格数组的行进行排序 NATSORTROWS
总结
对字符串/单元格/结构数组中的文本进行字母数字排序。考虑到任意数字子字符串的值,按字符代码对文本进行排序。例如:比较
>> 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 将所有连续数字解释为整数,可以使用正则表达式指定数字子串识别:参见 的作用 获取详细信息。
NATSORTFILES 不执行简单的自然顺序排序,而是分别对文件名和文件扩展名进行排序,以确保字典排序,其中较短的文件名总是在较长文件名之前排序。同样,文件路径在每个文件分隔符字符上被分割,文件层次结构的每一级都被单独排序。
例子与DIR ()
P =“C: \ SomeDir \子目录”
S = dir (fullfile (P,‘* . txt”));
S = natsortfiles(年代);
k = 1:元素个数(S)
F = fullfile (P, S (k) . name)
结束
文件的依赖
自然顺序排序由函数提供 的作用 (文件交换34464)。所有的 的作用 的可选输入由 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-old.m”“test.m”“test10.m”“test1.m”};
> >排序(B)错误号码顺序:
ans =
“test.m”
“test1.m”
“test10-old.m”
“test10.m”
“test2.m”
> > natsortfiles (B)%较短的名称之前较长:
ans =
“test.m”
“test1.m”
“test2.m”
“test10.m”
“test10-old.m”
% %目录名称:
>> c = {“A2-old \ 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-old \ test.m”
“A2 \ test.m”
> > natsortfiles (C)%较短的名称之前较长:
ans =
“A1 \ test.m”
“A1-archive.zip”
“A2 \ test.m”
“A2-old \ test.m”
“A10 \ test.m”
>> d = {“A1 \ B”“+ / B”“A / B1”“= / B '“\ B0”};
> >排序(D)
ans =“+ / B”“A / B1”“A1 \ B”“= / B '“\ B0”
> > natsortfiles (D)
ans =“\ B0”“A / B1”“A1 \ B”“+ / B”“= / 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.ru-cchi.com/matlabcentral/fileexchange/47434-natural-order-filename-sort), MATLAB中央文件交换。检索

Baidu
map