1
votes

I have been trying to add axis to a surf plot i have. I've tried various suggestions but can't get it to work. I have 3 matrices:

final -> 3460x300 double

spec -> 1x300 double (x-axis)

timedate -> 1x3460 double (y-axis)

The timedate matrix values are converted time and dates with date2num.

I tried

plot = surf(final);
set(plot,'LineStyle','none');

which gives me the correct graph but the axis are wrong. See image: enter image description here

When i try

[xx,yy] = meshgrid(spec,timedate)
plot2 = surf(xx,yy,final);
set(plot,'LineStyle','none');

It gives me the correct axis but the graph seems stretched enter image description here

How could i solve this?

Thanks in advance

1

1 Answers

1
votes

The second graph seems to be correct, the first one assumes a fixed distance between samples and the second one uses the complete info (x, y and z axis), below is a simplification of your problem:

Let's say you want to graph the curve described by the points (0.5, 1), (1, 2), (1.5, 3), (2, 4), the correct way of doing that is:

x = [0.5, 1, 1.5, 2];
y = [1, 2, 3, 4];
plot(x, y)

But you are doing:

plot(y)

Both graphs will show the same curve (because points are sampled with fixed distance in the x axis) but the points will be scaled and displaced along the X axis.

But, What if the points are now (0.5, 1), (1.2, 2), (1.4, 3), (2.2, 4)?:

plot(x,y) and plot(y) will show different curves because points were not sampled with fixed distance along the x axis, that's what happens in your problem.