필터 지우기
필터 지우기

Adding datenum to plots

조회 수: 18 (최근 30일)
David du Preez
David du Preez 2017년 5월 12일
답변: Peter Perkins 2017년 5월 12일
Hi. I have 2924 x 2 matrix. In column 1 is the daily datenum value from 2007-2016. These in are not necessarily continues as some data points have been removed. In column 2 is the data. I want to plot the data and indicate the years on the x-axis. I have tried this but it doens't work.
plot(data(1:2924,2))
datetick('x',11)

채택된 답변

KSSV
KSSV 2017년 5월 12일
% make some random data
startDate = datenum('02-01-1962');
endDate = datenum('11-15-2012');
x = datenum(linspace(startDate,endDate,50));
y = rand(1,50) ;
data = [x' y'] ;
figure
plot(data(:,1),data(:,2))
datetick('x','yyyy','keeplimits')

추가 답변 (1개)

Peter Perkins
Peter Perkins 2017년 5월 12일
In MATLAB R2014b or later (and especially in R2016b or later), consider using datetimes, not datenums.
startDate = datetime('01-Feb-1962');
endDate = datetime('15-Nov-2012');
x = linspace(startDate,endDate,50);
y = rand(1,50);
plot(x,y)
This figure automatically updates the ticks as you pan and zoom.

카테고리

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