How to plot all the points between two lines?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
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?
채택된 답변
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
The command plot(lat1(in),lon1(in),'r+') % points inside
Doesn't work

Where did the polar axes come from? You do not have any calls to polar() or polarplot() or to any mapping toolbox routines that might have a polar projection.
Okay My bad... I had to put the whole code so that it would become more clear.
This is what I'm doing..
Reading the data:
lat1 = xlsread('plot.xlsx', 'C2:C83400');
lon1 = xlsread('plot.xlsx', 'D2:D83400');
lat10 = [6.6038,21.841667]; lon10 = [94.4166,62.375000];
Renderind the data:
%% Render the recorded data
% Prepare figure
d=370400;
load coords %#ok<*UNRCH>
close all
opengl software % Hardware OpenGL rendering is unreliable for exporting images
figure('Renderer','opengl',...
'DefaultTextFontName', 'Miryad Pro', ...
'DefaultTextFontSize', 10,...
'DefaultTextHorizontalAlignment', 'right')
% Settings
centerLoc = [12.9716,77.5946]; % LEVC
lineColor = [0.7,0.7,0.7];
vertiExag = 5; % vertical exaggeration
markSize = 30;
maxRadius = 500e3; % bullseye max radius (m)
hold on
% Prepare UTM scenario
mstruct = defaultm('utm');
mstruct.zone = utmzone(centerLoc(1),centerLoc(2));
mstruct = defaultm(mstruct);
% Plot land contours
SHPdir = '.\SHPs\';
countries = shaperead([SHPdir 'ne_10m_admin_0_countries.shp'],...
'Selector',{@(x) strcmpi(x,'es'),'foo'},'UseGeoCoords', true);
% Change 'ES.VC' for the provinces/states of your preference or use a RegExp
% for all provinces: @(x) strcmpi(x,'ES.VC') => @(x) ~isempty(regexpi(x,'^ES.*$'))
provinces = shaperead([SHPdir 'ne_10m_admin_1_states_provinces.shp'],...
'Selector',{@(x) strcmpi(x,'ES.VC'),'region_cod'},'UseGeoCoords', true);
[x,y] = mfwdtran(mstruct,[countries.Lat provinces.Lat],[countries.Lon provinces.Lon]);
[xc,yc] = mfwdtran(mstruct,centerLoc(1),centerLoc(2));
[x1,y1]= mfwdtran(mstruct,lat1,lon1);
[x10, y10] = mfwdtran(mstruct,[lat10(1),lat10(2),lat10(1)-d,lat10(2)-d],[lon10(1),lon10(2),lon10(1),lon10(2)]);
Plotting:
% Plot bullseye
t = linspace(0,2*pi);
for i = 0:50e3:maxRadius
plot(xc+i.*cos(t),yc+i.*sin(t),'-','color',lineColor)
if i>0
text(xc+i-15e3, yc-15e3, [num2str(i/1e3) 'km'],'color',lineColor,'HorizontalAlignment','center');
end
end
% Plot lines
plot([xc xc],[yc-i-10e3 yc+i+10e3],'-','color',lineColor)
plot([xc-i-10e3 xc+i+10e3],[yc yc],'-','color',lineColor)
plot(x10,y10,'-','color','y');%plotting ats
plot(x10-d,y10,'-','color','y');%only for first batch
hold on ;
Why are you doing all that work with the bullseye yourself? Why not call polarplot(), or polar() if you have an older MATLAB ?
I haven't used polar plot so I made it by myself
I doesn't really matter, does it?
You are suffering from a misalignment of the polar plot with your other plots. It would be easier to figure out that problem if we were not having to debug the polar logic and the other logic at the same time.
Note: polar() is the older routine. It constructs the background plot and labels and so on, all in cartesian axes. If you were to overlay data on it, in the same axes, then the overlay would be specified in cartesian coordinates.
polarplot() is the newer routine that is more flexible in matters such as plotting only sectors and adjusting the label formats. It does not use cartesian coordinates at the user level. If you were to overlay data on it, in the same axes, then the overlay would be specified in polar coordinates.
Oh... alright!
I'll use polar instead of the bullseye, but how do I do the other thing?
You use inpolygon() like A. Sawas showed.
Make sure you get x and y right. Latitude corresponds to y, not to x.
Okay, thanks!
I'm still having the issue that even the cordinates which are outside the bound (in polygon cordinates) are being shown...
I didn't quite understand how to solve this.
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
This worked!!
Thanks a lot Sawas. :')
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기
제품
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
