How to concentrate time variables in separated columns for time series plot?

조회 수: 2 (최근 30일)
Xinyang Li
Xinyang Li 2019년 2월 3일
답변: Abhishek Singh 2019년 2월 10일
I'm new to Matlab, and I'm now working on a time series plot using a file whose hh:mm:ss are in 3 different columns.
How do I do to combine them to a single column? Or is it necessary to do so?
It would also be nice if there are some other ways that could show the time on x-axis.

답변 (1개)

Abhishek Singh
Abhishek Singh 2019년 2월 10일
Let’s break it down the problem into 2 parts:
1). Loading the data from file
Assuming the table is in this format, named as ‘time_file.txt’.
table_demo.png
You can load it into a matrix using:
timeseries_data = importdata('time_file.txt',',') % here ‘,’ being the delimiter
2). Converting it into datetime array
timearray = datetime(timeseries_data) %this is the datetime array that is being required
Remember that the datetime function takes arguments as (year, month, date).
If your matrix has columns in form (date, month, year), then overcome this using:
flipped_matrix = fliplr(timeseries_data) % this flips the matrix from left column to right
Now use timearray in plot function as x-axis.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by