资源简介
能根据时间、潮位数据,自动计算高潮位、低潮位及相应的时间和潮差值,出图并将计算结果保存在excel文件
代码片段和文件信息
clc
clear
Data=importdata(‘200901大横琴潮位.xls‘);
Level=Data.data;
TimeNum=datenum(Data.textdata(:1));
Time1=datetime(TimeNum‘ConvertFrom‘‘datenum‘);
%% 作图
figure(1)
subplot(211)
plot(Time1Level‘b-‘);
title(‘潮位变化过程图‘‘fontsize‘16);
ylabel(‘潮位/m‘‘fontsize‘16);
xlabel(‘时间‘‘fontsize‘16);
grid on;
hold on
%% 高潮位点&时间
N1=zeros;
for n=2:length(Level)-1
if Level(n-1)<=Level(n)&&Level(n)>=Level(n+1)
N1=[N1;n];
end
end
N1(1)=[];
for m=2:length(N1)-1
if Level(N1(m)) N1(m)=0;
end %
end
N1(N1==0)=[];
for h=2:length(N1)
if abs(N1(h-1)-N1(h))<=2
if N1(h-1)>=N1(h)
N1(h)=0;
else
N1(h-1)=0;
end
end
end
N1(N1==0)=[];
TimeGao=Time1(N1:);
for k=1:length(N1)
plot(Time1(N1(k)1)Level(N1(k))‘r*‘);
hold on;
end
clear m n k h
Gao=zeros;Lows=zeros;Temp=zeros;Temp2=zeros;Lowk=zeros;
for m=1:length(N1)-1
Gao(m)=Level(N1(m));
Testk=min(Level(N1(m):N1(m+1)));
Testkk=find(Level(N1(m):N1(m+1))==Testk);
Testkkk=N1(m)+Testkk-1;
Test=max(Testkkk);
Lowk=[Lowk;Test];
plot(Time1(Lowk(end))Level(Lowk(end))‘kp‘);
hold on
end
clear Temp Temp2 Test Testk Testkk Testkkk
%legend({‘Test‘‘高潮位点‘‘低潮位点‘}‘FontSize‘12)%‘‘);
legend(‘boxoff‘)
GaoLevel=Level(N1(1:end-1));
LowLevel=Level(Lowk(2:end));
GaoTime=datevec(TimeNum(N1(1:end-1)));
LowTime=TimeNum(Lowk(2:end));
GaoTemp=Data.textdata(N1(1:end-1));%时间数组转化成矢量
LowTemp=Data.textdata(Lowk(2:end));
DeltaHL=GaoLevel-LowLevel;
DeltaLH=LowLevel-Level(N1(2:end));
Exceltitle={‘高潮位时间‘‘高潮位值(m)‘‘低潮位时间‘‘低潮位值(m)‘‘超差(+)‘‘超差(-)‘};
xlswrite(‘ResultChaoWei11.xlsx‘Exceltitle‘sheet1‘‘A1‘);
xlswrite(‘ResultChaoWei11.xlsx‘GaoTemp‘sheet1‘‘A2‘);
xlswrite(‘ResultChaoWei11.xlsx‘GaoLevel‘sheet1‘‘B2‘);
xlswrite(‘ResultChaoWei11.xlsx‘LowTemp‘sheet1‘‘C2‘);
xlswrite(‘ResultChaoWei11.xlsx‘LowLevel‘sheet1‘‘D2‘);
xlswrite(‘ResultChaoWei11.xlsx‘DeltaHL‘sheet1‘‘E2‘);
xlswrite(‘ResultChaoWei11.xlsx‘DeltaLH‘sheet1‘‘F2‘);
subplot(212)
bar(Time1(N1(1:end-1)1)DeltaHL‘FaceColor‘[000.8]‘BarWidth‘1);
hold on
bar(Time1(Lowk(2:end)1)DeltaLH‘FaceColor‘[0.800]‘BarWidth‘1.5);
legend({‘落潮潮差‘‘涨潮潮差‘}‘FontSize‘12);
legend(‘boxoff‘);
legend(‘Location‘‘northwest‘);
title(‘潮差值分布图‘‘fontsize‘16)
ylabel(‘潮差值/m‘‘fontsize‘16);
xlabel(‘时间‘‘fontsize‘16);
grid on;
set(gcf‘position‘[100 100 1600 900]);
saveas(gcf‘0901大横琴‘‘jpg‘) ;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2713 2018-10-18 17:39 Tide.m
----------- --------- ---------- ----- ----
2713 1
评论
共有 条评论