Plotting time in hours

조회 수: 11 (최근 30일)
Luke Ainsworth
Luke Ainsworth 2022년 11월 24일
답변: Seth Furman 2022년 12월 6일
I have attached a .csv file which I have created containing time running from 21/11/22 - 22/11/22.
I have also attached a copy of the code i am using to load in this data.
I am not sure if the hh:mm time is correct in the .csv file? I want it to run from midnight on 21/11/22 to midnight on 22/11/22 at hourly intervals. For example, 21/11/22 01:00:00, i want this to be 1am.
I want to plot this data as a time series, showing the time in hours on the x-axis.

답변 (2개)

Florian Bidaud
Florian Bidaud 2022년 11월 24일
You have one line per hour so you can use directly the line index as your time series and plot the associated variable according to it.
timeSeries = 0:length(excelTime);
plot(timeSeries,variableToPlot)
  댓글 수: 1
Luke Ainsworth
Luke Ainsworth 2022년 11월 24일
I am using this function to plot the code
function plot_21_OC(data21)
plot(data21.t,data21.MSLP,'b-+') %for example
ylabel('MSLP')
I have attached an image of the figure. The data for MSLP is plotting, im just confused how i would get the appropriate times to plot on the x-axis.

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


Seth Furman
Seth Furman 2022년 12월 6일
tt = readtimetable("208cw3_21OC.csv",NumHeaderLines=5,VariableNamingRule="preserve")
tt = 25×6 timetable
time MSLP (hPa) Temperature (°C) Relative Humidity (%) Rainfall Rate (mm/hr) Wind Speed (kn) Visibility ________________ __________ ________________ _____________________ _____________________ _______________ __________ 21/11/2022 00:00 1007.8 9.5 94 0 5.2 7 21/11/2022 01:00 1006.4 10.5 92 0 6.1 7 21/11/2022 02:00 1004.3 10.8 91 0 7 7 21/11/2022 03:00 1001.8 11.5 88 0 6.1 7 21/11/2022 04:00 999.4 11.6 88 0 10.4 7 21/11/2022 05:00 996.8 11.6 91 0 12.2 6 21/11/2022 06:00 995.2 10.3 93 2.2 5.2 5 21/11/2022 07:00 992.8 10.2 95 3.6 6.1 5 21/11/2022 08:00 989.5 10.7 96 4.2 2.6 4 21/11/2022 09:00 987.2 11.2 97 1.4 6.1 6 21/11/2022 10:00 988.3 9.8 97 2.6 6.1 6 21/11/2022 11:00 988.6 9.4 96 0.2 10.4 7 21/11/2022 12:00 989.2 10.1 87 0 12.2 7 21/11/2022 13:00 990.1 8.4 86 0 12.2 7 21/11/2022 14:00 990.5 8.9 84 0 7.8 7 21/11/2022 15:00 990.3 8.2 85 0 11.3 7
stackedplot(tt)

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by