Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Xinyang Li
Xinyang Li le 3 Fév 2019
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.

Réponses (1)

Abhishek Singh
Abhishek Singh le 10 Fév 2019
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.

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by