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?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Mili Kian
il 18 Apr 2020
Commentato: Mili Kian
il 24 Apr 2020
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 Commenti
Risposta accettata
Image Analyst
il 18 Apr 2020
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 Commenti
Image Analyst
il 20 Apr 2020
Those points are just a grid:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285986/image.png)
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?
Più risposte (1)
Mili Kian
il 21 Apr 2020
2 Commenti
Image Analyst
il 21 Apr 2020
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/286460/image.png)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!