How to plot time data at different intervals?

조회 수: 1 (최근 30일)
B.kun
B.kun 2014년 9월 17일
댓글: Star Strider 2014년 9월 17일
Hi all
I have data as follows:
Date: (Column 1)
08:06:2012
08:06:2012
09:06:2012
10:06:2012
13:06:2012
Time:(Column 2)
13:56:52
13:59:32
14:08:27
03:05:48
03:11:34
var_1:(Column 3)
0.448584
0.445232
0.414100
0.236846
0.239984
I want to plot var_1 but as you can see, the date and time are not given at same intervals. If I create an array with all seconds for all days (so that they are equally spaced), then it would take a lot of space since I have 3 years of data.
Any suggestions on how to plot this without creating an equally spaced time intervals with blank values for missing data of var_1 in the data file? I still need to have the gaps of missing date/time data on my plots though. I tried using the timeseries code as below, but it doesn't work because it still requires my data to be equally spaced...
x = var_1;
ts1 = timeseries(x,1:6);
ts1.Name = 'Secondsly Count';
ts1.TimeInfo.Units = 'seconds';
ts1.TimeInfo.StartDate=Date(1,1);
ts1.TimeInfo.Format = 'mmm dd, yyyy HH:MM:SS';
ts1.Time=ts1.Time-ts1.Time(1);
plot(ts1)
Thank you.
  댓글 수: 1
Stephen23
Stephen23 2014년 9월 17일
Most plot commands in MATLAB don't need evenly spaced data... try it, and see what happens!

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

답변 (1개)

Star Strider
Star Strider 2014년 9월 17일
If you want to plot them, the interval between the measurements should not be a problem. They don’t have to be equally-spaced. Combine the date and time, create date numbers from them with datenum, and plot. Use datetick to help with your x-axis tick labels.
  댓글 수: 2
B.kun
B.kun 2014년 9월 17일
Thank you for the suggestion! This is what I tried and it worked: I combined the date and time into one column and plotted using the datetick.
DateTime = datenum(Date) + datenum(Time) - datenum('00:00','HH:MM');
%newdatecolumn = datestr(DateTime);
figure
plot(DateTime,var_1,'o')
dateFormat = 'dd-mm-yy';
datetick('x',dateFormat)
I hope this works with my original huge dataset too.. ^^"
Star Strider
Star Strider 2014년 9월 17일
My pleasure!

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

카테고리

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