MATLAB Answers

HELP Plotting hourly time series data

조회 수: 3(최근 30일)
Darcy Brady
Darcy Brady 2021년 7월 28일
편집: dpb 2021년 7월 28일
I am trying to write a code for a timeseries that will be used to analyse 3-months worth of hourly data sets (such as temperature, windspeeds ect) however, for some reason I can only seem to get it to plot the monthly time scales.. any help on how to datetick to mm dd yy HH mn?
uvFile = 'C:/Users/darcy/OneDrive/Desktop/Darcy/temp and detections/TEMPTOC.csv';
fid = fopen(uvFile,'r');
fgets(fid) %9 numbers of titles columns, data columns are in yyyy-mm-d(check)
fclose(fid);
fid = fopen(uvFile,'r');
%this loop instructs title columns before data starts to be skipped
for i = 1 : 1
fgets(fid);
end
c = 0;
%the numbers below indicate the column numbers which the data is found for
%the computer to read them
while ~feof(fid)
clear tmp;
tmp = fgets(fid);
c = c + 1
MM(c) = str2num(tmp(1:2));
dd(c) = str2num(tmp(4:5));
yy(c) = str2num(tmp(7:8));
HH(c) = str2num(tmp(10:11))
mn(c) = str2num(tmp(13:14))
ss(c) = str2num(tmp(16:17))
dc(c) = str2num(tmp(22:34));
end
fclose(fid);
%check the data looking
figure(1); clf
plot(dn,dc,'b-')
xlabel('Time')
ylabel('Wind Speed')
set(gca,'fontsize',12)
datetick
grid on
legend('Wind Speed')
dn = datenum(yy,mm,dd,H,M,S)

채택된 답변

dpb
dpb 2021년 7월 28일
편집: dpb 2021년 7월 28일
Use the builtin tools and datetime instead of deprecated datenum/datetick
uvFile = 'C:/Users/darcy/OneDrive/Desktop/Darcy/temp and detections/TEMPTOC.csv';
% title columns before data starts to be skipped
data=readtable(uvFile);
...
has a good chance of return everything in a table with the first column already being a datetime
But without knowing what the format of the datestring is, we can't write a specific 'InputFormat' string if it isn't one that is automagically recognized...
But, with datetime instead, you get a time axis automagically without the hassles of datetick
I'll note, though, that it will undoubtedly be too crowded to have hourly tick marks regardless -- 3 months @ 30 d/m * 24 h/d --> 2160 hrs -- while a monitor may have 1980 pixels horizontally.

추가 답변(0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by