Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to add date (year and Month) on x-axis for a series dataset?

Subject: how to add date (year and Month) on x-axis for a series dataset?

From: Kuo-Hsien

Date: 31 May, 2012 23:46:46

Message: 1 of 2

Hi all,

I have a dataset at a daily time step from 2000 to 2010. It does't come with timestamp, however the dataset was printed day by day.

I plot this dataset, but I do not know how to show the year and month datetick on x axis.

Please show me how to do this.

Many thanks.

Michael

Subject: how to add date (year and Month) on x-axis for a series dataset?

From: TideMan

Date: 1 Jun, 2012 02:21:13

Message: 2 of 2

On Friday, June 1, 2012 11:46:46 AM UTC+12, Kuo-Hsien wrote:
> Hi all,
>
> I have a dataset at a daily time step from 2000 to 2010. It does't come with timestamp, however the dataset was printed day by day.
>
> I plot this dataset, but I do not know how to show the year and month datetick on x axis.
>
> Please show me how to do this.
>
> Many thanks.
>
> Michael

You'll need to generate a timestamp:
% Figure out the start and finish times
t1=datenum('20000101','yyyymmdd');
tn=datenum('20100101','yyyymmdd');
% Generate the time vector at daily intervals
t=[t1:tn]';
% Generate some random data for plotting
y=randn(length(t),1);

clf
plot(t,y)
datetick('x',12)

You'll need to make sure your timestamp t has exactly the same number of elements as your data.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us