How do you create a surf plot in cylindrical coordinates?

191 ビュー (過去 30 日間)
Jeremy Pearson
Jeremy Pearson 2012 年 11 月 17 日
In general, the syntax for a surf plot is surf(X,Y,Z). I have u = F(r,z). I'd like to do surface plots of u for multiple cross sections at z = h1, h2, h3, etc. Is there a simple way to create a surf plot in cylindrical coordinates, i.e., something that would be analagous to the syntax: surf(r,phi,u) where u = u(r,h1)?

採用された回答

Jonathan Epperl
Jonathan Epperl 2012 年 11 月 19 日
Or even easier, remember that you're not forced to put just one variable X in the first argument of surf, all you need is a parametrization. So in your case, assume you have vectors r and phi. Then make them into a grid, obtain a matrix with z-values using your function F and just plot:
[R PHI] = meshgrid(r,phi);
Z = F(R,PHI); % which assumes your function is vectorized
surf(R.*cos(PHI), R.*sin(PHI), Z);
  1 件のコメント
Jeremy Pearson
Jeremy Pearson 2012 年 11 月 19 日
Jonathan,
Works great! I had to modify the code a little bit to get it to work since F is a function of r and z and not r and phi, but your tip put me in the right direction. This is the code I entered:
>> [r,theta] = meshgrid(linspace(0,0.7,30),linspace(0,2*pi,30));
>> flux = F(r,meshgrid(linspace(0.4,0.4,30))); % new meshgrid defines z
>> surf(r.*cos(theta),r.*sin(theta),flux);
I may have not had to create and extra meshgrid and define everything in linspace but I just fiddled with it until it worked.
Thanks for all your help!
Jeremy

サインインしてコメントする。

その他の回答 (2 件)

Matt J
Matt J 2012 年 11 月 17 日
Use TriScatteredInterp to interpolate your data onto a cartesian grid. Then plot using SURF as usual.

Teja Muppirala
Teja Muppirala 2012 年 11 月 19 日
You can use POL2CART to convert the data from r/theta to x/y and then call SURF.
[R,TH] = ndgrid(0:0.1:5,linspace(0,2*pi,41));
F = @(r,th) sin(th).*sinc(1+r);
Z = F(R,TH);
[X,Y] = pol2cart(TH,R);
surf(X,Y,Z);

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by