How do I plot timeseries, including event like earthquake?

조회 수: 4 (최근 30일)
Umay Ana
Umay Ana 2019년 12월 19일
댓글: Umay Ana 2019년 12월 24일
Hello
I have two files and their sizes are not same. Files consist of two columns such as date and value.
Date format is ISO 8601 such as 2019-12-30T01:15:14
Value format is float-number.
How do I plot time series to see details?
Regards...

답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 12월 22일
Hi,
In this case, use one of these data import options:
(1) data import using uiimport('DATA_file_name.txt') that creates a table variable containing two column of data, viz date and values
(2) data import using importdata('DATA_file_name.txt') that creates structure type of data containing dates and data values.
(3) data import: textscan() ==> FID= fopen('DATA_file_name.txt'); DATA = textscan(FID, '%s %f'); fclose(FID);
The dates can be read with the command datenum(), e.g.,: DD = datenum('2019-12-30T01:15:14', 'yyyy-mm-ddTHH:MM:SSZ')
To plot the imported dates and data values: plot(DD, Values)
xlabels of dates can be displayed with datetick()
Good luck.
  댓글 수: 1
Umay Ana
Umay Ana 2019년 12월 22일
편집: Umay Ana 2019년 12월 22일
Thank you for your guide. I try to apply the steps but I cannot read text file using textscan.
fileID = fopen('filename.txt');
C = textscan(fileID, '%{yyyy-MM-ddTHH:mm:ss}D %f', 'Delimiter', ' ');
fcloseID;

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


Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 12월 22일
Here is corrected code:
fileID = fopen('filename.txt', 'r');
C = textscan(fileID, '%s %f'); % Presumably your file does not have headerlines (texts, etc). It contains only two columns
fclose(fileID);
  댓글 수: 1
Umay Ana
Umay Ana 2019년 12월 24일
I don't understand why
% {...}D
doesn't work.
Why did you suggest using datenum? I don't want to see x-axes such as serial date number.
fileID = fopen('filename.txt', 'r');
C = textscan(fileID, '%s %f');
fclose(fileID);
formatIn= 'yyyy-mm-ddTHH:MM:SS';
date = datenum(C{1,1},formatIn);
value = C{1,2};
% Class of date and value are double now.
plot(date,value)
y-axes is normal, not x-axes. Which date, month, day, hour, minute etc.?

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

카테고리

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