Plot 3d figure (surface) with one time-dimension axis

Hello,
I'm trying to plot: surf(d,t,v)
where:
d is a vector - consists of integer values, e.g. d=[10 11 12 .... 46]
v is an input matrix - consists of integer values, in dimension d x t
t is a vector - consists of one-minute time steps over the defined period, e.g. t= [14:33 14:34 14:35 .... 18:21]
So far, I've been able to plot the surface using some "dummy" values for y-axis (t=[1 2 3...120]). Does anybody know how to plot such surface and having the y-axis in hh:mm format? The problem is that when I'm using the dummy values, the graph contains no relevant information about time (y-axis is scaled in the integer values)

Answers (2)

For y axis having time in HH:MM format, first convert the time you have to datenum
doc datenum
Then plot the graph using the datenum value on y and to show it in the HH:MM format on the graph use datetick
doc datetick

3 Comments

Thank you for help.
I'm just struggling with some bugs. I've tried this (d and velocity are defined as integer vectors, no problem)>
tm = [16:34 16:35 16:36 16:37 16:38 16:39 16:40 16:41 16:42 16:43];
s = datestr (tm);
t = datenum (s);
s1 = surf(t,d,velocity);
I think problem is with datestr (s has dimension 235 x 11) or datenum (t has dimension 235 x 1). But at the end, it should be plot on x-axis as data with the dimension 1 x 10.
tm = {'16:34';'16:35';'16:36';'16:37';'16:38';'16:39';'16:40';'16:41';'16:42';'16:43'};
datenum(tm,'HH:MM')
Well, your code proceeded without any bug, however then it has "squeezed" the surface into a single line.
My plot looks like this:
%%
tm = {'16:34';'16:35';'16:36';'16:37';'16:38';'16:39';'16:40';'16:41';'16:42';'16:43'};
t = datenum(tm,'HH:MM');
s1 = surf(t,d,velocity);
datetick('x','hhmm')
shading interp;
colormap jet;
freezeColors
hold on;
m1 = surf(t,d,control);
datetick('x','hhmm')
alpha (m1, 0.4);
colormap winter;
As you can see, I'm plotting two surfaces into the one image and both of them were actually reduced into the line (in extent of the x-axis)

Sign in to comment.

I used an alternative way with re-labeling the axis: set(gca,'XTickLabel'['16:34';'16:35';'16:36';'16:37';'16:38';'16:39';'16:40';'16:41';'16:42';'16:43';'16:44'])
But it's quite annoying. First I have to prepare "dummy" values and then I have to define these labels following syntax 'label1';'label2';....
It's not really smooth way :D

Asked:

on 3 Apr 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!