필터 지우기
필터 지우기

How to plot all the points between two lines?

조회 수: 2 (최근 30일)
Rakshit R
Rakshit R 2019년 4월 6일
댓글: Rakshit R 2019년 4월 8일
So, I have one line that goes from these lat lons :
lat10 = [6.6038,21.841667]; lon10 = [94.4166,62.375000];
plot(x10,y10,'-','color','y');%plotting the line
plot(x10-d,y10,'-','color','y');%plotting a line parallel to the above line
now I'm reading a set of cordinates from an excel sheet :
lat1 = xlsread('101010.xlsx', 'B2:B300');
lon1 = xlsread('101010.xlsx', 'C2:C300');
I want to only plot the points which are within these two lines.If any one point is not in between the lines, I don't want to plot anything. Please help me with how I can do this?

채택된 답변

A. Sawas
A. Sawas 2019년 4월 6일
편집: A. Sawas 2019년 4월 6일
It seems that you have an area inside a parallelogram defined by four points. Then you can use the inpolygon method as follows:
% find the X of the four points
X = [lat10(1),lat10(2),lat10(1)-d,lat10(2)-d];
Y = [lon10(1),lon10(2),lon10(1),lon10(2)];
% the X and Y of the other points which may or not be inside the parallelogram
lat1 = xlsread('101010.xlsx', 'B2:B300');
lon1 = xlsread('101010.xlsx', 'C2:C300');
[in,on] = inpolygon(lat1,lon1,X,Y);
% (in) contains the indices of the points inside the parallelogram
% (on) contains the indices of the points on the parallelogram
% do some plots
figure
plot(X,Y) % parallelogram
hold on;
plot(lat1(in),lon1(in),'r+') % points inside
plot(lat1(~in),lon1(~in),'bo') % points outside
hold off
  댓글 수: 13
A. Sawas
A. Sawas 2019년 4월 8일
Using the details you provided try this code:
X = [x10,fliplr(x10)-d];
Y = [y10,fliplr(y10)];
[in,on] = inpolygon(x1,y1,X,Y);
% (in) contains the indices of the points inside the parallelogram
% (on) contains the indices of the points on the parallelogram
% do some plots
%plot(X,Y) % parallelogram
plot(x1(in),y1(in),'r+') % points inside
plot(x1(~in),y1(~in),'bo') % points outside
Rakshit R
Rakshit R 2019년 4월 8일
This worked!!
Thanks a lot Sawas. :')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by