How to plot six concentric circles using meshgrid and plot?

6 ビュー (過去 30 日間)
Yuval
Yuval 2013 年 3 月 27 日
I am trying to plot six concentric circles using meshgrid() and plot(). The circles' radii vary between 0.5 and 1.75 (with intervals of 0.25). I am wondering whether the code below is sufficiently efficient and whether indeed it should be performed as delineated below:
theta = linspace(0, 2*pi, 50);
[X, Y] = meshgrid(0.5:0.25:1.75, theta);
plot(a+cos(Y).*X, b+sin(Y).*X);
?
  1 件のコメント
Image Analyst
Image Analyst 2013 年 3 月 27 日
Yeah - it does, but so? What is the question?

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

採用された回答

Matt J
Matt J 2013 年 3 月 27 日
You could conserve a little memory if you did it this way, but I don't know anyone who cares about efficiency for such a small plotting task,
theta = linspace(0, 2*pi, 50).';
R=0.5:0.25:1.75;
plot(a+cos(theta)*R, b+sin(theta)*R);
  8 件のコメント
Yuval
Yuval 2013 年 3 月 27 日
編集済み: Yuval 2013 年 3 月 27 日
I mean I ran mine, the original one I posted here, in which the transpose was clearly omitted, and yet the plot was just as that generated by your own code, with the transpose. Is that still impossible? Did you mean to suggest that that is strictly mandatory if R is defined as you proposed? Please allow me to re-post what works perfectly fine on this machine:
theta = linspace(0, 2*pi, 50); R = 0.5: 0.25: 1.75; [X, Y] = meshgrid(R, theta); plot(a+cos(Y).*X, b+sin(Y).*X);
Matt J
Matt J 2013 年 3 月 27 日
編集済み: Matt J 2013 年 3 月 27 日
Yes, the transposition of theta was only relevant to my proposed approach -- the one that does not use meshgrid. Notice that you use elementwise .* multiplication whereas I use pure matrix multiplication '*'. Matrix multiplication requires the operands to be appropriately shaped.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by