Number of points that passes a line

2 ビュー (過去 30 日間)
Abdulkarim Almukdad
Abdulkarim Almukdad 2020 年 11 月 5 日
The attached data contains x and y values. Assuming they are walking in 1 direction per axis i.e. some people move from left to right thus x always increases, other people move from south to north. How can I find the number of people who passes a certain line? i.e. min(x)= -4, max(x)= 4, I want to find the number of people who passes my line x(from -4 to 0) y(0).

採用された回答

KSSV
KSSV 2020 年 11 月 5 日
編集済み: KSSV 2020 年 11 月 5 日
You can calculate the intersection points of your (x,y) data and the given line. To find the intersection points you can use this file exchange: https://in.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections
Let L1 be your (x,y) walking data and L2 be your line data.
P = InterX(L1,L2) ;
Your L1, L2 should be row matrices of size 2*m and 2*n. Where first row corresponds to x and second row correspond to y. The number of points P, you got is what you want.
  3 件のコメント
KSSV
KSSV 2020 年 11 月 5 日
I have seen your data..it has 178*27 matrix....If you have (x,y) pairs it should be having a even number of columns. And your max and min x-value is huge i.e [ -627.88 524.25]. When I try to use interX, with the lines [-4 to +4] , I am not getting any intersection points, But if you extend this line to say -800 to +800, you will get some intersection points. Check the below:
num = xlsread("01) 90.xlsx") ;
num(:,3) = [] ; % some extra column present, so remove it
x = num(:,1:2:end) ;
y = num(:,2:2:end) ;
x = x(:) ;
y = y(:) ;
L1 = [x' ; y'] ;
m = 100 ;
L2 = [linspace(-800,800,m); zeros(1,m)] ;
P = InterX(L1,L2) ;
plot(x,y,'r')
hold on
plot(L2(1,:),L2(2,:),'b')
plot(P(1,:),P(2,:),'*k')
Abdulkarim Almukdad
Abdulkarim Almukdad 2020 年 11 月 5 日
Thanks a lot KSSV, that was very helpful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by