TA的每日心情 | 怒 2019-11-20 15:22 |
|---|
签到天数: 2 天 [LV.1]初来乍到
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
+ Y4 c2 |& K) U3 t) O
- %从2005年.xls读取数据
- clc
- clear
- close all
- %%
- xlsdata={};%存放提取数据
& @9 l5 `- z7 \3 e. n* }& m- count=12;
- for j=1:count
- fprintf('正在读取2005年.xls第%d个sheet...n',j);
- [data text raw] = xlsread('2005年.xls',j);%读取Sheet j的数据,单元格为数字的存放到data(非数字的为Nan),为字符串的存放到text(非字符串的为空),raw中无论数字还是字符串,因为它是cell类型
- * v# w- \ \8 z
- %实际使用随意
- colume=0;
- for i=1:length(text(:,1))
- for k=1:length(text(1,:))
- if strcmp(raw{i,k},'汽车')
- colume=i;
- temp=raw{colume,10};
- break;
- end
- end
- end
- ) T9 y& y! b8 s5 V3 E- e8 y
- if colume==0
- continue;
- fprintf('本Sheet未找到想要数据!n');
- end
- xlsdata(j,1)={sprintf('2005年%d月',j)};
- xlsdata(j,2)={sprintf('统计')};
- xlsdata{j,3}=temp;%cell类型注意{}与()的区别
- fprintf('读取完毕!n');
- end
3 q" u+ h5 D9 T- 5 O2 |2 W% M+ U! `, v
- fprintf('数据正在写入整理.xls文件...n');
- xlswrite('数据整理.xls',xlsdata(2:count,:),1);%写入xls数据
- fprintf('数据成功写入整理.xls文件!n');, ?1 c5 A! E9 i6 ^
4 h$ |1 N- A" h* }7 `: V
|
|