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:
datetick for interval more than 1

Subject: datetick for interval more than 1

From: edward kabanyas

Date: 6 Sep, 2011 08:12:10

Message: 1 of 5

Hi all,

I want to use datetick, but for interval more than 1 because if step being 1, the tick is not readable for my case, theforefore I plan to use step is 3 or 4. So far I use the following code: (for 2004 May)

firstDays = datenum(2004,5,1:30,0:23,0,0);

set(gca, 'YTick', firstDays);
datetick('y','mm/dd','keepticks');

I work, but the tick is every day May/1, May/2....May/30, I want to get: May/1, May/4...(step 4). Do you have experience with this kind of problem ? If so, I really appreciate it for your sharing.

Edward

Subject: datetick for interval more than 1

From: dpb

Date: 6 Sep, 2011 13:34:16

Message: 2 of 5

On 9/6/2011 3:12 AM, edward kabanyas wrote:
> Hi all,
>
> I want to use datetick, but for interval more than 1 because if step
> being 1, the tick is not readable for my case, theforefore I plan to use
> step is 3 or 4. So far I use the following code: (for 2004 May)
>
> firstDays = datenum(2004,5,1:30,0:23,0,0);
>
> set(gca, 'YTick', firstDays);
> datetick('y','mm/dd','keepticks');
>
> I work, but the tick is every day May/1, May/2....May/30, I want to get:
> May/1, May/4...(step 4). Do you have experience with this kind of
> problem ? If so, I really appreciate it for your sharing.
...

You set a set of ticks to one-day intervals then told datetick() to keep
them; that's exatly what it did...but now you're not happy! :)

Create the tick label numbers w/ datenum() as you did but use the
spacing (hence the length of the output array also) desired if you want
a specific set.

--

Subject: datetick for interval more than 1

From: Steven_Lord

Date: 6 Sep, 2011 13:38:14

Message: 3 of 5



"edward kabanyas" <djuky_hmi@yahoo.com> wrote in message
news:j44kkq$q8d$1@newscl01ah.mathworks.com...
> Hi all,
>
> I want to use datetick, but for interval more than 1 because if step being
> 1, the tick is not readable for my case, theforefore I plan to use step is
> 3 or 4. So far I use the following code: (for 2004 May)
>
> firstDays = datenum(2004,5,1:30,0:23,0,0);

This doesn't work for me. DATENUM complains because 1:30 and 0:23 don't have
the same number of elements. Do you mean you want a tick for each day in
May? If so, use:

firstDays = datenum(2004, 5, 1:30, 0, 0, 0);

To see the dates, I plotted them versus some "dummy data":

plot(ones(size(firstDays)), firstDays);

> set(gca, 'YTick', firstDays);
> datetick('y','mm/dd','keepticks');
>
> I work, but the tick is every day May/1, May/2....May/30, I want to get:
> May/1, May/4...(step 4). Do you have experience with this kind of problem
> ? If so, I really appreciate it for your sharing.

You explicitly told MATLAB you wanted ticks each day (from the way you
constructed firstDays and your SET call) and you told DATETICK "don't change
the ticks I already specified." If that's not what you want, tell MATLAB
something different.

firstDays = datenum(2004, 5, 1:3:30, 0, 0, 0);
plot(ones(size(firstDays)), firstDays);

set(gca, 'YTick', firstDays);
datetick('y','mm/dd','keepticks');

You may want to add 5/30 to your firstDays vector explicitly; counting from
1 by steps of 3 doesn't get you to 30 exactly, so it's not part of 1:3:30
and thus 5/30 is not part of firstDays.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: datetick for interval more than 1

From: dpb

Date: 6 Sep, 2011 14:04:04

Message: 4 of 5

On 9/6/2011 8:38 AM, Steven_Lord wrote:
.> "edward kabanyas" <djuky_hmi@yahoo.com> wrote in message
> news:j44kkq$q8d$1@newscl01ah.mathworks.com...
...

>> firstDays = datenum(2004,5,1:30,0:23,0,0);
>
> This doesn't work for me. DATENUM complains because 1:30 and 0:23 don't
> have the same number of elements....

I wondered at that, too, Steve...turns out must be a revision in later
release(s). My (very old) R12 seems to simply ignore the second hourly
vector and creates the daily one w/o complaint...

(Just for record....)

--

Subject: datetick for interval more than 1

From: edward kabanyas

Date: 7 Sep, 2011 02:09:26

Message: 5 of 5

Hi Dear All !

Thanks for your reply. Finally, I use the following solution:

set(gca, 'YTick', [firstDays(1):4:firstDays(end)]);

Cheers
Edward

dpb <none@non.net> wrote in message <j45991$lsp$1@speranza.aioe.org>...
> On 9/6/2011 8:38 AM, Steven_Lord wrote:
> .> "edward kabanyas" <djuky_hmi@yahoo.com> wrote in message
> > news:j44kkq$q8d$1@newscl01ah.mathworks.com...
> ...
>
> >> firstDays = datenum(2004,5,1:30,0:23,0,0);
> >
> > This doesn't work for me. DATENUM complains because 1:30 and 0:23 don't
> > have the same number of elements....
>
> I wondered at that, too, Steve...turns out must be a revision in later
> release(s). My (very old) R12 seems to simply ignore the second hourly
> vector and creates the daily one w/o complaint...
>
> (Just for record....)
>
> --

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