i have number of points that have (x,y) .then i define a line and i want to realize which points are under the line?
조회 수: 2 (최근 30일)
이전 댓글 표시
i have number of points that have (x,y) .then i define a line and i want to realize which points are under the line?
i write this :
....
r=[0 10 15 20 30];
t=[10 10 15 10 10];
f= line(r,t)
axis([0,30,0,20]);
d=(eldof(:,10))& (eldof(:,11)) <= f
then all of points are zero
why??
댓글 수: 0
채택된 답변
Image Analyst
2020년 4월 18일
You need to call polyfit:
coefficients = polyfit(r, t, 1);
or you can call fitPolynomialRansac if you want the line to go exactly through the points on the bottom of your plot.
Then you have to get some x values and get a digital vector of line values. You can use your r locations, or you can use more or less than that. Then see which values are less than the y value of the line. For the same r points
yLine = polyval(coefficients, r);
belowLine = t < yLine; % A logical index vector.
댓글 수: 2
Image Analyst
2020년 4월 20일
Those points are just a grid:

I'm not sure what to do either. Can you draw the line on there that you want to detect if some point is below that line, and repost your picture with the line indicated?
추가 답변 (1개)
Mili Kian
2020년 4월 21일
댓글 수: 2
Image Analyst
2020년 4월 21일
Try this:
xy = [...
1 1
1 3
1 5
1 7
1 9
1 11
1 13
1 15
1 17
3 1
3 3
3 5
3 7
3 9
3 11
3 13
3 15
3 17
5 1
5 3
5 5
5 7
5 9
5 11
5 13
5 15
5 17
7 1
7 3
7 5
7 7
7 9
7 11
7 13
7 15
7 17
9 1
9 3
9 5
9 7
9 9
9 11
9 13
9 15
9 17
11 1
11 3
11 5
11 7
11 9
11 11
11 13
11 15
11 17
13 1
13 3
13 5
13 7
13 9
13 11
13 13
13 15
13 17
15 1
15 3
15 5
15 7
15 9
15 11
15 13
15 15
15 17
17 1
17 3
17 5
17 7
17 9
17 11
17 13
17 15
17 17];
x = xy(:, 1);
y = xy(:, 2);
plot(x, y, 'b.', 'MarkerSize', 20);
grid on;
% Make line
xRedLine = unique(x)
redLine = [8, 8, 8, 10, 13.1, 10, 8, 8, 8];
hold on;
plot(xRedLine, redLine, 'r+-', 'LineWidth', 3, 'MarkerSize', 15);
% Find values less than the red line for each x and plot a red square around them
for k = 1 : length(x)
thisX = round(x(k))
index = find(thisX == xRedLine);
if y(k) < redLine(index)
plot(thisX, y(k), 'rs', 'MarkerSize', 20);
end
end

참고 항목
카테고리
Help Center 및 File Exchange에서 Array and Matrix Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!