1

I am confused by the plotting of a 3D graph. Firstly, the matrix for x and y-axis are shown below.

x =
 0    71   142   213   284   355   426
 0    71   142   213   284   355   426
 0    71   142   213   284   355   426
 0    71   142   213   284   355   426
 0    71   142   213   284   355   426
 0    71   142   213   284   355   426

y =
 0     0     0     0     0     0     0
71    71    71    71    71    71    71
142   142   142   142   142   142   142
213   213   213   213   213   213   213
284   284   284   284   284   284   284
355   355   355   355   355   355   355

and the data is shown below.

Data =
   16       16       16       27       29      24       21
   17       17       15       26       29       16      16
   15       13       12       25       34       14      15
   12       10        9       28       18       11      11
   77        9        6       62        7        9       8
    4        4        4      131        3        4       6

Then I used this code.

mesh(x,y,Data)
xlabel('x')
ylabel('y')
zlabel('Data')

And I got this graph:

enter image description here

What I am confused by is why the point of Data(6,4)=131 is at point (1,4) in the graph. Also, you can see that the point of Data(5,1)=77 is at the point (1,2) in the graph. Why does the position of any points in the graph reverse in up-down direction with the position in the matrix? Is this a normal thing? Or, is there any problem in my code.

I am newcomer in Matlab but feel this up-down reversed plot is strange in my common sense.


(Edit) Thanks Dan, then I will describe why the exact shape of data is important to me. My work is to measure some specific parameter, such as humidity, in a room. The "spatially" measured result is shown "exactly" below.

16       16       16       27       29      24       21
17       17       15       26       29       16      16
15       13       12       25       34       14      15
12       10        9       28       18       11      11
77        9        6       62        7        9       8
 4        4        4      131        3        4       6

According to the data, the humidity in the South direction of the room is highest (131). However, when I make a graph in MATLAB, the point 131 turns to be at the North direction of the "Mathematical model" as shown in the graph above. So, it makes me difficult to put that graph into a report. I know that I can rotate the graph but if I rotate, the origin point turns to be strange and also causes other left-right reverse problem instead. You may say that my graph is Mathematically correct but it is still strange to make a report with this reverse problem. Is there any way to fulfill this task? I have tried to reverse the data in up-down and left-right direction in the matrix but it doesn't help.

2
  • flip your Y variable before calling mesh. i.e. mesh(x,flipud(y),Data). When you plot a graph, conventionally you want the y axis to increase as it goes up on the left hand side. But that's the opposite of what your data does, it increases y as it goes down. Your graph is correct as you have specified it, like I said it is your y that is wrong.
    – Dan
    Feb 12, 2014 at 11:15
  • 1
    Thanks a lot Dan. At last I understood. You helped me so much!!
    – Yossiri
    Feb 13, 2014 at 7:26

1 Answer 1

1

The point with value 131 is not at point (1,4) in your graph at all but rather at x-y-point (213,355) which is exactly correct. All you need to do to get what it sounds like you desire is rotate the image... there is nothing wrong here. It is very simple to rotate from the figure window, or else you could do it programatically too

3
  • Thank you for your answer. Yes, I can rotate the graph so that the position of value 131 is at the down side of the graph as same as that in the matrix. The picture is here. dl.dropboxusercontent.com/u/153995/prob2.tif But I noticed two issues in this graph. 1) Even though the point 131 is at the suitable direction, the point 77 is left-right reversed compared with the 77 in the matrix. 2) Normally, the point of x and y at the origin of the graph should be 0,0 but in case of this graph it is 400,500.
    – Yossiri
    Feb 12, 2014 at 8:35
  • Yes but don't forget that in your data, the y values ascend as the rows ascend, but when printed the rows increase down your screen. So your graph is right, if anything you are looking at your data matrices upside down...
    – Dan
    Feb 12, 2014 at 8:54
  • Thanks Dan, I added more information but it is difficult to write a lot in an additional comment. So I added it into the main question.
    – Yossiri
    Feb 12, 2014 at 9:40

Your Answer

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

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