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

1 Ansicht (letzte 30 Tage)
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.

Antworten (1)

Abhishek Singh
Abhishek Singh am 10 Feb. 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.

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by