Plot date and time
1 回表示 (過去 30 日間)
古いコメントを表示
I have date and time values that I'd like to use for my XTick values. The data is in an array that has date, time and price. I would like to plot my price across multiple days and each time interval, 5 minute intervals. How can I set this up? Is it possible to set XTick to every 1.5 hours or every 18 ticks?
This is what I have right now but it doesn't accomplish what I want:
the array is 415x3 set like [date time price]
date = datenum(date,'mm/dd/yy');
time = datenum(time,'HH:MM');
count = length(time);
plot(price, count)
Thanks for your help!
0 件のコメント
回答 (1 件)
Thomas
2012 年 3 月 29 日
If you have date and time as cell's in Vectors date in format cell{mm/dd/yy} time in format cell{HH:MM:SS}
1) concatenate them
dt_time=[date time];
2) convert cell to mat
dt_time_new=cell2mat(dt_time);
3) convert to datenum here
final_time=datenum(dt_time_new,'mm/dd/yyHH:MM:SS');
plot(final_time,price)
datetick('x','mm/dd','keepticks') % or which ever format you want
7 件のコメント
KRUNAL
2014 年 8 月 12 日
編集済み: KRUNAL
2014 年 8 月 12 日
Thomas I tried using it. It says datenum failed for line 23
This is my code.
clc;
clear all;
orginf = '<filename>';
sheet = 'Sheet1';
for n =1:151
xlrange = ['C' num2str(n+1)];
a = xlsread (orginf,sheet,xlrange);
if a==1
range = ['E' num2str(n+1)];
range1 = ['F' num2str(n+1)];
range2 = ['S' num2str(n+1)];
[~,~,b] = xlsread(orginf,sheet,range);
c = xlsread(orginf,sheet,range1);
d = {datestr(c,'HH:MM:SS')};
dt_time = [b,d];
[~,~,mag] = xlsread(orginf,sheet,range2);
mag_new = double(cell2mat(mag));
dt_time_new=cell2mat(dt_time)
final_time=datenum(dt_time_new,'mm/dd/yyHH:MM:SS'); %line 23
plot(final_time,mag_new)
datetick('x','mm/dd','keepticks')
end
end
and my data in the various columns are as follows :
Stage Magnitude Date Time
1 -1 06/10/2012 17:56:50
1 -3 06/10/2012 17:59:33
2 -2 06/11/2012 8:52:45
2 -5 06/11/2012 8:52:46
3 -3 06/12/2012 9:11:37
3 -4 06/12/2012 9:55:56
3 -1 06/12/2013 9:57:46
4 -5 06/12/2013 10:47:49
4 -2 06/12/2013 10:48:08
4 -4 06/12/2013 10:50:35
5 -3 06/12/2013 7:47:43
5 -1 06/12/2013 8:15:30
5 -2 06/12/2013 8:16:04
I am trying to plot magnitude v/s date time. Please suggest me what is wrong with it ?
参考
カテゴリ
Help Center および File Exchange で Time Series Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!