Hello, I am trying to plot circles and then get rid of the circles touching the axis as shown when you run my code. After this, I am trying to find the distance between these circles so as to know the circle that is farthest from the rest. THANKS

1 回表示 (過去 30 日間)
%generate random numbers
%centers of circle
x = rand(100,1);
y = rand(100,1);
centers = [x y];
radii = 0.05.*ones(length(x),1);
% %clear the axis
cla
% %fix the axis limits
xlim([0 1])
ylim([0 1])
% %set the axis aspect ratio to 1:1
axis square
box on
%display the circles
viscircles(centers,radii, 'Color','k');
for i = 1:1:length(x)
if x(i) >= 0.9
x(i) =[];
y(i) =[];
end
end
%This is not working, though the circles are plotting well

採用された回答

KSSV
KSSV 2018 年 11 月 13 日
編集済み: KSSV 2018 年 11 月 13 日
As you have the centers of circles (xnew,ynew) in hand..you can use distance formula/ pdist2/ pdist and get the distances between circles.
%generate random numbers
%centers of circle
x = rand(100,1);
y = rand(100,1);
centers = [x y];
radii = 0.05.*ones(length(x),1);
% %clear the axis
cla
% %fix the axis limits
xlim([0 1])
ylim([0 1])
% %set the axis aspect ratio to 1:1
axis square
box on
%display the circles
viscircles(centers,radii, 'Color','k');
idx = x<0.9 ;
xnew = x(idx) ;
ynew = y(idx) ;
  3 件のコメント
KSSV
KSSV 2018 年 11 月 13 日
YOu need not use a loop.....read about logical indexing......welcome to MATLAB. :)
Jide Williams
Jide Williams 2018 年 11 月 13 日
Thanks but the circles are still touching the edges of the axis. Did you run the code?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by