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:
Is it possible to apply dynamic date ticks on imagesc plots?

Subject: Is it possible to apply dynamic date ticks on imagesc plots?

From: Camille Couzi

Date: 2 Nov, 2010 19:48:03

Message: 1 of 5

Hi
i am working with images created with th sc function (see http://www.mathworks.com/matlabcentral/fileexchange/16233).
I would like xtick labels to appear as dates, using perhaps the dynamic date ticks function (see http://www.mathworks.com/matlabcentral/fileexchange/27075-intelligent-dynamic-date-ticks). apparently they work on normal plots, but not on imagesc and sc...
Anybody who have an idea?
I also tried to apply a manually way to put these ticks by writing:


set(gca,'XTickMode','auto');
xt=get(gca,'XTickLabel')
for i=1:length(xt)
    vt(i)=time_in_datenum_format(xt(i),1);
end


vtd=datestr(vt,'dd-mm-yyyy HH:MM') %to put them on datestr format

set(gca,'XTickLabel',{datestr(vt,'dd-mm-yyyy');datestr(vt,'HH:MM')});

but that don't work fine when I zoom in or out, and then change the matrix I display in my axes...

Thanks for reply!
Camille.

Subject: Is it possible to apply dynamic date ticks on imagesc plots?

From: Leah

Date: 2 Nov, 2010 19:57:05

Message: 2 of 5

You have to get the corrent labels which I assume are Date numbers and then set them to date strings. I do this like so:

set(gca, 'xticklabel', datestr(get(gca,'xtick'),'mmm-yy'))

I'm not sure what you mean by zooming in and out. If you set xlim/ylim inside your code do this after. If you are zooing in a gui, then put this inside the callback. Hope this helps.

Subject: Is it possible to apply dynamic date ticks on imagesc plots?

From: Camille Couzi

Date: 2 Nov, 2010 20:20:05

Message: 3 of 5

Hi Leah!
Thanks for replying so fast!
That worked, the only thing is that I need to make appear datestr in that format:
'dd-mm-yy HH:MM'
but as it is too long, sometimes I can't see well the tick. can you help me to set dd-mm-yy in the first line and HH:MM in the second line?
Thanks a lot!
Camille.

Subject: Is it possible to apply dynamic date ticks on imagesc plots?

From: Camille Couzi

Date: 3 Nov, 2010 14:15:06

Message: 4 of 5

Hi again Leah
I have been trying your proposition, and at the beginning I though it was working (that explains my last "hip hip hip hourra" message), but in fact yes, I am having a problem when zooming in and on. I am working with a GUI, there is an axes in my figure, and a panel of buttons, each button represent a matrix that I display in the imagesc in the axe.

So if I write
xt=get(gca,'XTick') it gives me the right xticks, but then if I zoom, xt don't refresh, so I keep the same Xticks.
Thats why when I do after that :
set(gca, 'xticklabel',datestr(h.Vtime_pre(get(gca,'xticklabel')),'dd-mm-yy'))
 and I zoom, I always get the same xticklabels.

How can I do to get xt refreshed when I zoom in and out meanwhile I keep the same matrix displayed in the imagesc?

I have been searchig other solutions and tried the my_xticklabels function, but the result is really not great..

I hope this message is clear, sorry for my baf english...
Thanks in advance for your help!

Subject: Is it possible to apply dynamic date ticks on imagesc plots?

From: Leah

Date: 3 Nov, 2010 14:38:03

Message: 5 of 5

You need to set the xtick labels inside the zoom callback also
here's how it works on a command line
H1=imagesc(rand(100,100));
set(gca, 'xticklabel', datestr(get(gca,'xtick'),'mmm-yy'));
zoom in using zoom button, your labels are all wrong, but the underlying numbers are right
set(gca, 'xticklabel', datestr(get(gca,'xtick'),'mmm-yy'));

I've never used the zoom callback before, try researching ActionPostCallback
Good Luck!

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