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 件のコメント
Rakshit R
2019 年 4 月 7 日
The command plot(lat1(in),lon1(in),'r+') % points inside
Doesn't work

Walter Roberson
2019 年 4 月 7 日
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 ;
Walter Roberson
2019 年 4 月 7 日
Why are you doing all that work with the bullseye yourself? Why not call polarplot(), or polar() if you have an older MATLAB ?
Rakshit R
2019 年 4 月 7 日
I haven't used polar plot so I made it by myself
Rakshit R
2019 年 4 月 7 日
I doesn't really matter, does it?
Walter Roberson
2019 年 4 月 7 日
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.
Rakshit R
2019 年 4 月 7 日
Oh... alright!
I'll use polar instead of the bullseye, but how do I do the other thing?
Walter Roberson
2019 年 4 月 7 日
You use inpolygon() like A. Sawas showed.
Make sure you get x and y right. Latitude corresponds to y, not to x.
Rakshit R
2019 年 4 月 7 日
Okay, thanks!
Rakshit R
2019 年 4 月 7 日
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
Rakshit R
2019 年 4 月 8 日
This worked!!
Thanks a lot Sawas. :')
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Graph and Network Algorithms についてさらに検索
製品
参考
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
