필터 지우기
필터 지우기

How to draw a perfect circle and distance calculation

조회 수: 6 (최근 30일)
amj
amj 2018년 3월 9일
댓글: amj 2018년 3월 11일
Hi,
I got 2 issues:
  1. to draw a perfect circle
  2. to calculate a perfect distance
This is my code:
load fisheriris
rng(1); % For reproducibility
n = size(meas,1);
idx = randsample(n,1)
X = meas(~ismember(1:n,idx),3:4); % Training data
Y = meas(idx,3:4)
MdlKDT = KDTreeSearcher(X) % not used by mahanalobis
MdlES = ExhaustiveSearcher(X) % Prepare an exhaustive nearest neighbors searcher.
r = 0.3; % Search radius
IdxKDT = rangesearch(MdlKDT,Y,r)
IdxES = rangesearch(MdlES,Y,r)
[IdxKDT IdxES]
cellfun(@isequal,IdxKDT,IdxES)
figure;
plot(X(:,1),X(:,2),'.k');
hold on;
plot(Y(:,1),Y(:,2),'*r');
Mdl = KDTreeSearcher(X)
[n,d] = knnsearch(Mdl,Y,'k',10);
ctr = Y - d(end);
diameter = 2*d(end);
% Draw a circle around the 10 nearest neighbors.
h = rectangle('position',[ctr,diameter,diameter],...
'curvature',[1 1]);
h.LineStyle = ':';
If i used the fisheriris data, it is works well. But if i'm using Faithful Geyser data (the data as in the attachment), the circle becomes weird. The distance calculation as shown in second picture with yellow color also effected where the data points do not lie within a circle.. This is the code to apply the faithful data:
faithfuldat = xlsread('faithful.csv');
fData = faithfuldat(:,:);
[n,dim]=size(fData);
idx = randsample(n,1)
X = fData(~ismember(1:n,idx),:); % Training data
Y = fData(idx,:)
I really appreciate if anyone could advice me how to improve the circle and distance.

채택된 답변

Image Analyst
Image Analyst 2018년 3월 9일
편집: Image Analyst 2018년 3월 9일
To draw a circle, you can use rectangle(), viscircles(), or the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F
Add
axis equal;
to your code after you plot to make your circles look circular on the screen.
  댓글 수: 11
amj
amj 2018년 3월 10일
Dear image analsyt,if so, i would try tomorrow. i have been trying since his morning. I'm still could not fix it
amj
amj 2018년 3월 11일
Dear Image Analyst,
I modified the code:
xx = (range(diff(X(:,1))))
yy = (range(diff(X(:,2))))
ratio = (xx / yy) /sqrt(2)
for j = 1:length(Y)
c = Y(j,:)
Yx = c(1);
Yy = c(2);
pos = [c-r (2*r) (2*r)/ratio];
rectangle('Position',pos,'Curvature',[1 1])
end
axis([1 5.5 45 95])
Unluckily, the central points are not lie in center part. If you could advice an improvement, i would be grateful

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by