MATLAB Answers

drawing a best fit graph

52 views (last 30 days)
emeka onwochei
emeka onwochei on 2 Mar 2021
Commented: KSSV on 4 Mar 2021
is there a way to draw a best fit graph from a cut off circle, i have the [x y] coordinates for the first black points. now i want to use these coordinates to draw the exact shape on a graph. i tried polyfit but it doesnt give me the required shape
  1 Comment
KALYAN ACHARJYA
KALYAN ACHARJYA on 2 Mar 2021
Can you provide data or code to produce the plot shown?

Sign in to comment.

Answers (1)

KSSV
KSSV on 2 Mar 2021
I = imread('image.png') ;
I = rgb2gray(I) ;
[y,x] = find(~I) ;
% Get center
idx = boundary(x,y) ;
x = x(idx) ;
y = y(idx) ;
imshow(I)
hold on
plot(x,y,'r')
  9 Comments
KSSV
KSSV on 4 Mar 2021
I would suggest you this:
I = imread('image.png') ;
I = rgb2gray(I) ;
[y,x] = find(~I) ;
% Get center
idx = boundary(x,y) ;
x = x(idx) ;
y = y(idx) ;
%% Get circle radius and centre ;
% select three points randomly on circle
idx = [10 100 150] ;
pt1 = [x(idx(1)) y(idx(1))] ;
pt2 = [x(idx(2)) y(idx(2))] ;
pt3 = [x(idx(3)) y(idx(3))] ;
[C, R] = calcCircle(pt1, pt2, pt3) ;
%% Draw circle
th = linspace(0,2*pi) ;
xc = C(1)+R*cos(th) ;
yc = C(2)+R*sin(th) ;
imshow(I)
hold on
plot(xc,yc,'r')

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!