2

I have 2 vectors and one matrix and I would like to make a surface plot.

  1. first vector A , the distance vector A=1:1:100 (size 1 100);
  2. second vector B, the time vector B=1:1:10 (size 10);
  3. matrix C, every column has the data for each value of B (size 100 10)

How could I use the meshgrid and/or the surf function for getting a surface 3D plot?

1 Answer 1

2
[AA, BB] = ndgrid(A,B);
surf(BB,AA,C)

Or use the version of surf that allows two vectors as its two first inputs:

surf(B,A,C)

which for your particular vectors ([1 2 ...]) could be simplified to the single-input version

surf(C)
6
  • Thank you so much! works fine! if you know also how to fill with color or projection the side walls will be perfect! Feb 25, 2014 at 15:16
  • ALSo, in my program, after the 10th value of B, B as C increase their size (B size 11, 12, 13 .. and C size 100 11, 100 12, 100 13 ... ). Please, is possible to use the same function ndgrid for having a surface plot after the 10th value? and how ? Feb 25, 2014 at 15:42
  • @user1640255 As for color projection: I don't know how; and it wasn't in the original question. For the increased size, can't you use the same approach?
    – Luis Mendo
    Feb 25, 2014 at 15:56
  • I will try. My program has 2 parts. The first part is until the time vector take value 10. Afterwards the A and C increase their size together. So, for B=1:1:12 (size 12), I have A=1:1:102 (size 1 102) and C (size 102 12). IS little tricky... Feb 25, 2014 at 16:13
  • Sorry, I have confused. The size is the same. What happen is that the C is filled only in 50% of the 100 values, rest filled with zero. After the the 10th time vector value, the C goes to 55%, 60% etc. SO, A=1:1:100 (size 1 100) 2. B=1:1:12 (size 12) 3. matrix C, (size 100 12). I am confused now. Feb 25, 2014 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.