From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Plot Cylindrical coordinates
Date: Thu, 1 Jan 2009 21:58:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 17
Message-ID: <gjje99$e30$>
References: <>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1230847081 14432 (1 Jan 2009 21:58:01 GMT)
NNTP-Posting-Date: Thu, 1 Jan 2009 21:58:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:509439

Lorenzo <> wrote in message <>...
> I need to plot some pressure values upon a circle, so I have to work in cylindrical coordinates, ma I couldn't find a way to do it...
> The problem is this: I have the pressures values taken at some point upon the cylinder surface, the values I have are simple scalar, so I have a pressure vector: P=[p1 p2 p3 p4...] and every pressure value is taken for a certain angle upon the circular cylinder surface, TH=[th1 th2 th3 th4...] so what I want is: draw a circle (and I know how to do it) and then plot every pressure value for every angle starting from the circle border and going away from it...
> Any idea?
> Thanx
> Lorenzo

  I am not completely clear about what you are proposing to do, Lorenzo.  Do the pressures you have vary with distance along the axis of the cylinder as well as with the angle about that axis?  If so, it sounds as though you are attempting to flatten these cylindrical coordinates of axial distance and angle into a circular annulus where radial distance replaces the previous distance along the cylinder axis.  What gives me that idea is your statement "draw a circle ... and then plot every pressure value for every angle starting from the circle border and going away from it."  Indeed that would allow you to depict your results with a 'surf' plot, even if it is somewhat of a distortion of the original cylinder.

  As 'someone' says, for this you need 'meshgrid' to generate rectangular matrices of R and A values (radial distance and angle) over some mesh of values that corresponds to the P values you have.  That is, with each R(i,j) and A(i,j) the value in P(i,j) should be the corresponding pressure, (and consequently your three matrices R, A, and P must all be of the same size for each dimensions.)  With 'pol2cart' you can then convert R and A into corresponding X and Y matrices, and then use X, Y, and P in 'surf'.

  Don't be discouraged by the rather misleading statement in matlab's 7.5 document about 'surf' that you "Use surf and surfc to view mathematical functions over a rectangular region."  Your annulus certainly isn't a rectangular region.  However, it is the index space that 'surf' needs to have rectangular, not the x and y coordinate space, as you will see further on in the "Algorithm" section.

  It also occurs to me that, contrary to the above, your pressures might be varying only with angle and you wish to depict this in a two-dimensional plot using pressure as radial distance from a center and varying with the angle.  That is a much easier problem.  Use angle and pressure as the respective theta and rho inputs to 'pol2cart' to get vectors x and y, and then use 'plot' with x and y.  No surfaces are involved.

Roger Stafford