Converting HH:MM:SS into decimal days to make a time series

조회 수: 2 (최근 30일)
emily bristow
emily bristow 2020년 12월 12일
댓글: emily bristow 2020년 12월 12일
I need to make a timeseries across three days (7th June - 9th June 2010) - I'm unsure how to include both the time and days across the x-axis?
I think I need to convert into decimal days but I'm unsure on how to do this and combine both days and time.
Seperate timeseries plots need to be made for the mean phosphate and nitrate concentrations in surface and bottom waters, again I'm not sure how to do this!
Any help will be grateful, the excel sheet is attached.
  댓글 수: 1
dpb 2020년 12월 12일
Use the datetime type. plot is already aware of date axes with it.

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 12월 12일
편집: Cris LaPierre 2020년 12월 12일
Use a datetime. When you plot, your data type is honored. You can use xtickformat to format how the data appears.
% Define date and time formats for import
opts = detectImportOptions("CTD12-17.xlsx");
% nice, but not necessary
opts.VariableNamingRule = "preserve";
opts = setvartype(opts,"Time","duration");
opts = setvaropts(opts,"Time","InputFormat","hh:mm:ss","DurationFormat","hh:mm:ss");
% Set datetime format for Date + Time
opts = setvartype(opts,"Date_TimeCombined","datetime");
opts = setvaropts(opts,"Date_TimeCombined","InputFormat","dd/MM/yy HH:mm:ss");
% Load data
data = readtable("CTD12-17.xlsx",opts)
data = 6x7 table
Date Time Date + Time Combined Bottom Water Mean N+N Surface Water Mean N+N Bottom Water Mean P Surface Water Mean P ___________ ________ ____________________ _____________________ ______________________ ___________________ ____________________ 07-Jul-2010 04:55:00 07/07/10 04:55:00 10.24 5.38 0.68 0.43 07-Jul-2010 15:06:38 07/07/10 15:06:38 8.77 3.11 0.64 0.5 07-Jul-2010 22:21:32 07/07/10 22:21:32 9.86 4.84 9.67 0.39 08-Jul-2010 04:12:44 08/07/10 04:12:44 9.86 4.84 0.67 0.39 08-Jul-2010 20:31:47 08/07/10 20:31:47 9.81 4.4 0.71 0.38 09-Jul-2010 02:35:24 09/07/10 02:35:24 10.46 3.43 0.7 0.32
plot(data.("Date + Time Combined"),data.("Bottom Water Mean N+N"))
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2020년 12월 12일
Ah, because the Date+Time column format is incorrect. I specified it as MM/dd/yy but it is actually dd/MM/yy. I've updated and rerun my original post.
emily bristow
emily bristow 2020년 12월 12일
Okay, thank you thats brilliant!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)


Help CenterFile Exchange에서 Time Series Events에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by