代码随记
% time => 2022/08/19
clc,clear,close all;
% 打开的文件
file_lujin = 'data/'; 
file_name = '1'; 
file_name = [file_name,'.xlsx']; file = [file_lujin,file_name];
% 读取的范围
sheet = '历史数据'; range = 'D2:H50000';
% 数据读取
[num, tex, raw] = xlsread(file,sheet,range);

% 空 cell
pad_data = {}; formatIn = 'yyyy-mm-dd HH:MM:SS';
for i=1:size(tex,2)
    pad_data=[pad_data, {''}];
end

%%%% 处理数据
% 日期格式转换
Data_noformat = tex(:,1); Data_format = datevec(Data_noformat,formatIn);
% 去除重复行
[B,ia,ib] = unique(Data_format,'rows'); dup = setdiff(1:size(Data_format,1),ia);
tex(dup,:) = []; Data_noformat = tex(:,1); Data_format = datevec(Data_noformat,formatIn);
% 时间周期 15 min
ys=15; t_k = [0,0,0,0,0,0];
Data_format_bj = [Data_format;t_k]; Data_format_j = [t_k;Data_format];
Data_format_use = Data_format_bj - Data_format_j; Data_format_use(1,:)=[0,0,0,0,15,0]; Data_format_use(end,:)=[];
% 去除相近行 相近值为 3 min
xjz = 3;
for i=1:xjz
    tex(Data_format_use(:,5)==i,:) = [];
end
Data_noformat = tex(:,1); Data_format = datevec(Data_noformat,formatIn);
Data_format_bj = [Data_format;t_k]; Data_format_j = [t_k;Data_format];
Data_format_use = Data_format_bj - Data_format_j; Data_format_use(1,:)=[0,0,0,0,15,0]; Data_format_use(end,:)=[];
% 误差判定 误差值为 3 min
wcz = 4;
for i=1:wcz
    Data_format_use(Data_format_use(:,5)==ys+i,5) = Data_format_use(Data_format_use(:,5)==ys+i,5) - i;
    Data_format_use(Data_format_use(:,5)==ys-i,5) = Data_format_use(Data_format_use(:,5)==ys-i,5) + i;
end
No_ys = find( Data_format_use(:,1)==0 & Data_format_use(:,2)==0 &((Data_format_use(:,3)*24+Data_format_use(:,4))*60 + Data_format_use(:,5) ~=ys));
% 插补日期
temp = 0; rep_s = 1000;
for i=1:length(No_ys)
    add_wz = No_ys(i)-1+temp;  add_data_all=[];
    add_data = Data_format(add_wz,:);
    add_data(6)=0;
    for ii=1:rep_s
        add_data(5) = add_data(5)+ 15;
        if add_data(5) >60
            mod_d=mod(add_data(5),60);
            add_data(4) =add_data(4) + (add_data(5)-mod_d)/60;
            add_data(5) = mod_d;
        end
        if add_data(4) >=24
            add_data(4)=0; add_data(3)=add_data(3)+1;
        end
        ppp_k = Data_format(add_wz+1,4);
        pp = (Data_format(add_wz+1,3)-add_data(3))*24*60 +(ppp_k-add_data(4))*60 + Data_format(add_wz+1,5) - add_data(5);
        add_data_all = [add_data_all;add_data];
        if  pp < 15+wcz && pp > 15-wcz
            break;
        end
    end
    add_tex_all = repmat(pad_data, size(add_data_all,1), 1);
    add_tex_all(:,1) = cellstr(datestr(add_data_all,formatIn));
    Data_format = [Data_format(1:add_wz,:); add_data_all; Data_format(add_wz+1:end,:)];
    tex = [tex(1:add_wz,:); add_tex_all; tex(add_wz+1:end,:)];
    temp = temp + size(add_data_all,1);
end
% 去除重复行
[B,ia,ib] = unique(Data_format,'rows'); dup = setdiff(1:size(Data_format,1),ia);
Data_format(dup,:) = [];
Data_format_bj = [Data_format;t_k]; Data_format_j = [t_k;Data_format];
Data_format_use = Data_format_bj - Data_format_j; Data_format_use(1,:)=[0,0,0,0,15,0]; Data_format_use(end,:)=[];
% 误差判定 误差值为 3 min
for i=1:wcz
    Data_format_use(Data_format_use(:,5)==ys+i,5) = Data_format_use(Data_format_use(:,5)==ys+i,5) - i;
    Data_format_use(Data_format_use(:,5)==ys-i,5) = Data_format_use(Data_format_use(:,5)==ys-i,5) + i;
end

No_yso = find( Data_format_use(:,1)==0 & Data_format_use(:,2)==0 &((Data_format_use(:,3)*24+Data_format_use(:,4))*60 + Data_format_use(:,5) ~=ys))

% 按需要进行排列
f_yyyy = unique(Data_format(:,1));
% 按年
b = {};
for i = 1:size(f_yyyy,1)
    a =tex(Data_format(:,1)==f_yyyy(i),:);
    L = max([size(a,1),size(b,1)]);
    a = [a; repmat(pad_data, L-size(a,1), 1)];
    if i ~= 1
        b = [b; repmat(pad_data, L-size(b,1), i-1)];
    end
    b = [a, b]; a = {};
end
% 按月
LL=size(b,1); W=size(pad_data,2); g = {};
for ii=1:size(b,2)/W
    e = b(:,(ii-1)*W+1:ii*W);
    LLL = size(cell2mat(e(:,1)),1);
    e(LLL+1:LL,:)=[];
    mData_noformat = e(:,1); mData_format = datevec(mData_noformat,formatIn);
    f_mm = unique(mData_format(:,2));
    for i = 1:size(f_mm,1)
        f =e(mData_format(:,2)==f_mm(i),:);
        L = max([size(f,1),size(g,1)]);
        f = [f; repmat(pad_data, L-size(f,1), 1)];
        if i ~= 1
            g = [g; repmat(pad_data, L-size(g,1), i-1)];
        end
        g = [f, g]; a = {};
    end
end
% 数据头
data_head = [{'采集时间'},{'井内非满管液位(米)'},{'井内满管液位(米)'},{'表面流速(m/s)'},{'瞬时流量(m3/s)'}];
data_head = repmat(data_head, 1, size(g,2)/size(data_head ,2));
g = [data_head; g];
% 数据写入
data_w = g; sheet_w = 'write'; range_w = '';
xlswrite(file,data_w,sheet_w,range_w)
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇