3

I've run simulations which have given me data points corresponding to X number of different radii, and Y number of angles each one was evaluated at. This means that I have X times Y data points which I need to plot.

I am currently plotting it in an non-ideal fashion: I am using the x and y axes as the r and theta axes. This means that my data appears as a sinusoidal trend which increases with radius on a Cartesian grid, not the circle which it physically represents. This is how I am currently plotting my data:

surf(r_val, th_val, v_val);

What I wish to do is plot my data on a cylindrical axis, such like that of the function polar(), but in R3 space. I would rather not download a toolbox, or modify the existing polar function; if there is no other solution then I will obviously end up doing this anyways.

Thanks for your help! G.

Also, I am using Matlab 2012a

EDIT:

r_val = 1x8 vector containing unique radii

th_val = 1x16 vector containing unique angles

v_val = 8x16 matrix containing voltages corresponding to each position

NOTE: (after answered)

The truly ideal solution does not exist to this problem, as Matlab currently supports no true polar axes methods. Resource found here.

gkiar
  • 480
  • 1
  • 6
  • 20

1 Answers1

5

You should transform your coordinates to Cartesian coordinates before plotting them. MATLAB has builtin functions for perfroming coordiante transformations. See, for example pol2cart, which transforms polar or cylindrical coordinates to Cartesian coordinates. In your case you would simply use something like:

[x, y] = pol2cart(th_val, r_val);

surf(x, y, v_val);

Edit: Given that th_val and r_val are vectors of differing lengths it is necessary to first create a grid of points before calling pol2cart, along the lines of:

[R, T] = meshgrid(r_val, th_val);
[x, y] = pol2cart(T, R);
surf(x, y, v_val);
Chris
  • 44,602
  • 16
  • 137
  • 156
  • That isn't a bad idea, and that is the first one I went to. The hurdle is this: the `surf(x,y,z)` function inputs a vector of length n for `x`, and a vector of length m for `y`, then `z` is an nXm matrix. By changing my r and theta to cartesian, the matrix values do no longer match (since I was using unique values of r and theta) – gkiar Jun 25 '12 at 13:15
  • what are the sizes of x,y,z in your case? – tmpearce Jun 25 '12 at 13:18
  • 2
    I'm not sure what you mean by *the matrix values do no longer match*. Perhaps you can update your question with more details. However, `surf` also accepts matrices for `x` and `y`. In this case `x`, `y` and `z` must all be the same size. Try something like `[R, T] = meshgrid(r_val, th_val)`, then `[x, y] = pol2cart(T, R);`. – Chris Jun 25 '12 at 13:19
  • See the edits for more information on the vectors. What I meant was that either `[x,y]=pol2cart(th_val, r)` would not compute (because I used unique values and they are different sizes), or if I did not use unique values, then the matrix dimensions would no longer match when using `surf(x,y,v_val)`. Thanks for your help. – gkiar Jun 25 '12 at 13:24
  • Also, this approach, which I have just implemented, does not give the ideal solution -- plotting the values on a cylindrical axis, where I can clearly and easily observe radius and angle. Again, thanks for your continued help! – gkiar Jun 25 '12 at 13:30
  • Then I'm afraid I don't really understand what you are expecting. If you plot your cylindrical coordinates on Cartesian axes you are of course going to get artifacts from the mismatch between coordinate systems. If this is a problem convert your grid to Cartesian and plot that. Since your grid is cylindrical of course this plot would appear as a cylinder. I'm afriad you'll have to specify more clearly what you are trying to achieve. Perhaps some example screenshots or example data which demonstrates why you are not happy with this solution? – Chris Jun 25 '12 at 13:35
  • This is a good solution, and I am very pleased, just trying to push it a bit further. The appearance of a cylinder is what I desire, but I wish for the Cartesian axes which it lies on to be Cylindrical axes. This is simply for the reason that I can easily observe the radius from the origin, and the angle, as opposed to just observing the (x,y) coordinates. Does this make things more clear? It is not how to plot it, but more how to turn the axes to a cylindrical axis much like the polar() plot function. – gkiar Jun 25 '12 at 13:40
  • Is something like [this solution](http://www.mathworks.co.uk/support/solutions/en/data/1-1951J/index.html?product=ML&solution=1-1951J) what you are after? – Chris Jun 25 '12 at 13:57
  • *"True polar axes are not supported in MATLAB."* This answered my question, that this is the best I am going to get. Thanks! Mind updating your answer to include the comment with the meshgrid? Then I'll accept it! Thank you again for all of your help! – gkiar Jun 25 '12 at 14:01