clc clear all filename1 = '.\内蒙古自治区锡林郭勒盟典型草原轮牧放牧样地群落结构监测数据集(201.csv' %对 fid = fopen('result3.txt','a+'); % % B = readmatrix(filename1) % L= length(B) % D = B(1:10560,14:15) [a,b,c]=xlsread(filename1); data = a(:,15)%%干重数据 % s1 = '第一轮牧后' % s2 = '中牧(6天)' sum = 0 % dd =b{2,2} % kl=strcmp(b{2,2},s1) % ggdd = unique(b{:,4}) year = [2016 2017 2018 2019 2020] fgh ={'牧前','第一轮牧后','第二轮牧后','第三轮牧后','第四轮牧后'} ssd ={'无牧(0天)','轻牧(3天)','中牧(6天)','重牧(12天)'} ggsd = {'G6','G8','G9','G11','G12','G13','G16','G17','G18','G19','G20','G21'} dfdd ={'2016.6.1', '2016.6.21', '2016.7.21', '2016.8.21', '2016.9.21', '2017.5.24', '2017.6.26', '2017.7.22', '2017.8.27', '2017.9.20','2017.9.30', '2018.5.15', '2018.6.25', '2018.7.22', '2018.8.21', '2018.9.21', '2019.5.10', '2019.6.26', '2019.7.24', '2019.8.26', '2019.9.18', '2020.5.29', '2020.6.29', '2020.7.20', '2020.8.14', '2020.9.17'} L5 =length(dfdd) L1 =length(year) L2 =length(fgh) L3 =length(ssd) L4 =length(ggsd) s1 =fgh{1,5} s2 =ssd{1,4} % fprintf(fid,'%d ,%s,%s, %5.2f,\n',year,fgh{1,kk2},ssd{1,kk3},sum); for kk2=1:1:L2 for kk5 =1:1:L5 for kk1=1:1:L1 for kk3=1:1:L3 sum =0 for i =1:1:length(data) if a(i,1) == year(kk1) && strcmp(b{i+1,2},fgh{1,kk2}) && strcmp(b{i+1,3},ssd{1,kk3}) && strcmp(b{i+1,4},dfdd{1,kk5}) sum = sum + data(i) end end if sum>0 fprintf(fid,'%d ,%s,%s, %s,%5.2f,\n',year(kk1),fgh{1,kk2},ssd{1,kk3},dfdd{1,kk5},sum); end end end end end fclose(fid);
结果最后都追加 到 result3.txt 中
标签:end,21,批处理,sum,length,fgh,malab,ssd,csv From: https://www.cnblogs.com/niuxiaojie521/p/16802446.html