Search code examples
matlabaxisfigurewaterfall

Limits of the Waterfall function ... or not?


I have a problem to figure out how in a waterfall figure the x axis can correspond to the x values, and not their point number. This question seems rather simple but in my particular case (due to the size of vectors) it's not easy to get the correct figure. So i really need your help ... after several hours of unsatisfied results.

Assuming that two vectors x and y of the same length are recorded at a time t. This procedure is performed k times. I finally want to plot with waterfall y versus x for the different times. I give you a script that corresponds to the experiment where xx is just added to get here two continuous functions x and y for the different times. The result is almost perfect but I would like the x-y values on the corresponding x, y axis instead of the point number.

xx=0:0.1:8;
for t=1:2:11
   x(t,:)=sin(t*xx.^2);
   y(t,:)=cos(t*xx.*4);
end
waterfall(x,y)

The problem comes probably from the different size of x, y with t. Thanks in advance for your advice.


Solution

  • Two comments:

    1. waterfall takes either Z or X,Y,Z as coordinates. So it takes your x matrix as Z, and the other argument is mapped to the C input, which dictates color. You can see that the plot is the same if you do waterfall(x), except with different colors.

    2. Your x is not monotonically increasing, so if you plot x(t,:) vs y(t,:) for any t, you'll get a web-like graph, not anything nice to look at.

    So I'll plot xx vs y, and I'm modifying your y a bit so it looks nicer. I hope you can take this idea and modify it to do what you need.

    The code below doesn't use waterfall at all, it simply calls plot3 once for each t. It might be possible to call plot3 with your full x and y matrices, but this is just as easy.

    In the plot3 call, the x-coordinates are given by xx, the y-coordinates by t (simply repeated to match the expected size), and the z-coordinates by y:

    xx = 0:0.1:8;
    for t = 1:2:11
       y = cos(t*xx/4);
       plot3(xx,repmat(t,size(xx)),y)
       hold on
    end
    xlabel('x')
    ylabel('t')
    zlabel('y=cos(tx/4)')
    

    enter image description here