2017-06-18 5 views
2

は、私はちょうどこのように、いくつかの同心円上のいくつかの点をプロットしたい:いくつかの同心円の点を順にプロットする方法は?

sample image

異なる円上の点の数が同じであると判断されるように。半径の差は同じです。

しかし、for関数を使用したい場合、私はi = 1:total number of pointsを定義するという問題に直面しています。私は正しい角度値を選択する方法を知らない。誰でも助けてくれますか?あなたはそのためpolarplotを使用することができます

R_steplength = 1; %difference of radius 
angle_point = 20; %total number of points on one circle 
max_R = 4; %outer radius of circle 
central_x = 1; % origin of concentric circle 
central_y = 1; 

total_circle_points = (max_R/R_steplength) * angle_point; %calculate total 
points 
fin_x= zeros(1, total_circle_points); %define output points position 
fin_y = zeros(1, total_circle_points); 

for i = 1:total_circle_points 
    for j = 1:angle_point 
     if rem(i+1, 20)~= 1 
      k = floor(i/20); 
      angles = linspace(0,2*pi,angle_point); 
      fin_x(i) = R_steplength*(k+1)*cos(angles(j))+central_x; 
      fin_y(i)= R_steplength*(k+1)*sin(angles(j))+central_y; 
     else 
      fin_x(i) = central_x + R_steplength*(k+2); 
      fin_y(i) = central_y + R_steplength*(k+2); 
     end 
     plot(fin_x(:),fin_y(:),'ro') 
    end 

end 

答えて

1

:ここ

ax = polaraxes; % create polar axes 
% calculate all points locations: 
[angles,rad] = meshgrid(0:angle_point:360,1:R_steplength:max_R); 
polarplot(ax,deg2rad(angles),rad,'r.') % plot all the points 
ax.GridColor = 'k'; % set grid color to black 
ax.GridAlpha = 1; 
ax.ThetaAxis.TickValues = 10:20:360; % set radius grid between the points 
ax.RAxis.TickValues = 1.5:R_steplength:(max_R+0.5); % set circles between the points 
ax.RAxis.Limits = [0 max_R+0.5]; % show the outer circle 

私が円を描くように軸のグリッドを使用する。ここ

は、私が書いたコードです。これが必要とされていない場合は、単に書くことができます。

[angles,rad] = meshgrid(0:angle_point:360,1:R_steplength:max_R); 
polarplot(ax,deg2rad(angles),rad,'r.') % plot all the points 

concentric circles

関連する問題