admin 发表于 2022-11-6 22:11:14

批量处理多个excel文件,读出指定单元格数据

%功能:批量读出多个excel文件的指定列数据,并从文件名提取输入幅度,绘制输入输出关系图
clc;clear;
s=what;
p=s.path;
file=dir();%拼接路径,读入all文件名
filenum=length(file);%文件数目
data=cell(1003,41); %定义数据大小,1000行,41个文件
for i=1:filenum
name=file(i).name;%文件 名称遍历循环
=xlsread();%读取数据
data(,i)=Raw(,15);%赋值:将excel文件的15列的6行到1005行数据赋给data。
temp1(i,:)=regexp(name,'DC','split'); %分列名字
temp2(i,:)=regexp(temp1(i,2),'.csv','split'); %二次分列名字
Input(i,1)=str2num(temp2{i,1}{1,1}); %提取输入幅度并赋值

data{1,i}=name;
data{2,i}=mean(cell2mat(data(,i)));
data{3,i}=std(cell2mat(data(,i)));
end
plot(Input',cell2mat(data(2,:)),'r*');
fit=polyfit(Input',cell2mat(data(2,:)),1)
hold on
Output_fit=polyval(fit,Input);
plot(Input',Output_fit','b--');
title('Input vs Output ','Fontsize',12,'Fontname','Times New Roman');
xlabel('Vinput(V)','Fontsize',10,'Fontname','Times New Roman');
xlim();
ylim();
ylabel('Dout(LSB)','Fontsize',10,'Fontname','Times New Roman');
h=text(2,4000,'$$ V_{input}=\frac{D_{out}+8106}{4812.7}$$');
set(h,'Interpreter','latex','Fontsize',10)
页: [1]
查看完整版本: 批量处理多个excel文件,读出指定单元格数据