drawing a best fit graph
이전 댓글 표시
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
KALYAN ACHARJYA
2021년 3월 2일
Can you provide data or code to produce the plot shown?
답변 (1개)
KSSV
2021년 3월 2일
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
emeka onwochei
2021년 3월 2일
emeka onwochei
2021년 3월 2일
Walter Roberson
2021년 3월 2일
why did you have [y,x] = find(~I) ; instead of [x,y]?
If you have a table of data, such as a logarithm table

then would find data by referring to "row 7, column 3" -- vertical distance named first, and then horizontal distance named.
This is the order that MATLAB uses for arrays. The first index is vertical distance, and the second index is horizontal distance.
However, the convention for Cartesian coordinates is that the independent variable, x, is along the vertical axes and is named first, followed by the dependent variable on the vertical axes second.
Row is vertical distance. Vertical distance is y. Therefore, row coordinates correspond to y, and column coordinates correspond to x.
Walter Roberson
2021년 3월 2일
why is it that when i remove the line imshow, the graph switches on the y axis.
imshow() does an automatic
set(gca,'Ydir','reverse')
unless hold is on for the axes. When you are dealing with images, it is very common to think of them in terms of distance down from the top, instead of in terms of distance up from the bottom (Cartesian coordinates.)
Yes, three incompatible conventions.
emeka onwochei
2021년 3월 2일
KSSV
2021년 3월 2일
Pick a point on circle, where you want a tangent. You have center and point in hand; get the slope, get the slope of tangent. Use point slope formula.
emeka onwochei
2021년 3월 2일
emeka onwochei
2021년 3월 3일
KSSV
2021년 3월 4일
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')
Refer the link https://in.mathworks.com/matlabcentral/fileexchange/19083-calccircle for the function calcircle.
카테고리
도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

