Matlab 文件打开读取操作

该博客介绍了如何使用Matlab进行自然顺序排序,特别是在处理包含数字的文件名时,如避免在排序时将'file10.txt'误排在'file2.txt'之前。文中提供了一个名为'sort_nat'的函数,可以实现数字在字符串中的数值意义排序。通过dir函数读取文件夹下的文件,并利用'sort_nat'进行排序。
摘要由CSDN通过智能技术生成

    files = dir(strcat(path));%读取文件夹下的文件
    files_name =sort_nat({files.name});%调整图片排名顺序
    for i=3:length(files_name)%从第3个开始,去掉前两个无用

    %  代码

    end

 

%sort_nat具体内容
function [cs,index] = sort_nat(c,mode)
%sort_nat: Natural order sort of cell array of strings.
% usage:  [S,INDEX] = sort_nat(C)
%
% where,
%    C is a cell array (vector) of strings to be sorted.
%    S is C, sorted in natural order.
%    INDEX is the sort order such that S = C(INDEX);
%
% Natural order sorting sorts strings containing digits in a way such that
% the numerical value of the digits is taken into account.  It is
% especially useful for sorting file names containing index numbers with
% different numbers of digits.  Often, people will use leading zeros to get
% the right sort order, but with this function you don't have to do that.
% Fo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值