MATLAB循环处理数据

文档转为Excel

clc;
clear;
close all;
wd_path= 'C:\Users\Administrator\Desktop\1.13\';   %文件夹路径 
wd_path_list = dir(strcat(wd_path,'*.txt'));      %%dir('.')列出当前目录下所有子文件夹和文件%
wd_num = length(wd_path_list);                    %文件的长度
Newexcel_path='C:\Users\Administrator\Desktop\1.13\';
opts = delimitedTextImportOptions("NumVariables", 17);
% 指定分隔符
opts.Delimiter = ",";
for i=1:wd_num
    filename = strcat('1.',num2str(i),'.txt');
    A = readtable(filename,opts);
    B = table2array(A);
    GPFPD_count=1;
    GTIMU_count=1;
    GPFPD=cell(ceil(size(B,1)/2+1),17);
    GTIMU=cell(ceil(size(B,1)/2+1),17);
    for j=1:size(B,1)   
        str=string(B{j,1});     %将导入的cell类型数据一行一行地提取出来 提取为string类型
        IsGPFPD=contains(str,"GPFPD");      %判断提取的string数据中是否包含有GPFPD
        IsGTIMU=contains(str,"GTIMU");
        if IsGPFPD
            GPFPD(GPFPD_count,:)=B(j,:);
            GPFPD_count=GPFPD_count+1;      %GPFPD数据条数+1
        end
        if IsGTIMU
            GTIMU(GTIMU_count,:)=B(j,:);
            GTIMU_count=GTIMU_count+1;
        end
    end
    sheet2=2;
    sheet3=3;
    xlswrite((strcat(Newexcel_path,int2str(i),'.xlsx')),GPFPD,sheet2);
    xlswrite((strcat(Newexcel_path,int2str(i),'.xlsx')),GTIMU,sheet3);
end
循环处理

clc;
clear;
close all;
excel_path= 'C:\Users\Administrator\Desktop\1.13\';   %文件夹路径 
excel_path_list = dir(strcat(excel_path,'*.xlsx')); %%dir('.')列出当前目录下所有子文件夹和文件%
excel_num = length(excel_path_list);            %文件的长度
Newexcel_path='C:\Users\Administrator\Desktop\1.13data\';   %若想对读取的Excel进行处理,新的excel存放地址
%img_name = sort({img_path_list.name});      %排序后的文件名
for i=1:excel_num
    gtimu=xlsread([num2str(i),'.xlsx'],'sheet3');
    W=gtimu(:,5);   %%陀螺仪Z轴角速率
    W=W'; 
    ax=gtimu(:,6);   %%X轴加速度
    ay=gtimu(:,7);   %%Y轴加速度
    az=gtimu(:,8)-0.98;   %%Z轴加速度
    a=sqrt(ax.^2+ay.^2+az.^2);
    a=a';
    W=W(1:100:end);
    a=a(1:100:end);
    gpfpd=xlsread([num2str(i),'.xlsx'],'sheet2');
    Xv=gpfpd(:,9);   %%X轴线速速
    Yv=gpfpd(:,10);  %%Y轴线速度
    Zv=gpfpd(:,11);  %%Z轴线速度
    Vv=sqrt(Xv.^2+Yv.^2+Zv.^2);  
    V=Vv(1:100:end);
    V=V';

    x_true = TODBT(gpfpd(:,7),gpfpd(:,6),gpfpd(:,8));
    plot(x_true(:,1),x_true(:,2))
    x_true=x_true';
    ZTtrain=[];
for U=1:100:length(x_true)
    A=x_true(:,U);
    Y=[ZTtrain,A];
    ZTtrain=Y;
end
plot(ZTtrain(1,:),ZTtrain(2,:))
path="C:\Users\Administrator\Desktop\1.13data\";
str=strcat(path,'JPG',num2str(i),'.jpg');
saveas(gcf,str);
B=[V;W;a;ZTtrain];
%xlswrite('data.xlsx',B,'Sheet1');
xlswrite((strcat(Newexcel_path,'data',int2str(i),'.xlsx')),B);
  
end
批量文档重命名

clc;
clear;
close all;
wd_path= 'C:\Users\Administrator\Desktop\1.14\';   %文件路径 
Newexcel_path='C:\Users\Administrator\Desktop\1.13\';
files = dir(strcat(wd_path,'*.txt'));      %%dir('.')列出当前目录下所有子文件夹和文件%
len = length(files);                    %文件的长度
for i=1:len
    oldname = files(i).name;
    newname=strcat('1.',int2str(i+54),'.txt');
    command = ['rename' 32 oldname 32 newname];
    status = dos(command);
    movefile(newname,Newexcel_path);
end

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

入坑的小白z

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值