find the mean of values which are inside the inpolygon

2 ビュー (過去 30 日間)
pruth
pruth 2015 年 10 月 29 日
回答済み: Chad Greene 2015 年 11 月 1 日
hi i have written a code for satellite data- file format HDF5. i have chosen a latitude longitude. also i plotted a map as i wanted (attached), but i don't know how to get mean of those values(red dots) which are inside the inpolygon. kindly see the fig so u can get idea about what i want.

採用された回答

Chad Greene
Chad Greene 2015 年 11 月 1 日
The inpolygon function makes this pretty easy. It tells you the indices of all points inside a given polygon. Here's an example:
% Define and plot some scattered data points:
lon = 100*rand(800,1);
lat = 100*rand(800,1)-60;
z = 10*sind(lat)+5*cosd(lon)+rand(800,1);
plot(lon,lat,'.','color',[.08 .69 .1])
% Define and plot a box of interest:
boxlat = [-5 -20 -20 -5];
boxlon = [48 48 62 62];
hold on
plot(boxlon,boxlat,'r-')
% Find indices of all data points inside the box:
ind = inpolygon(lon,lat,boxlon,boxlat);
% Plot the data points inside the box:
plot(lon(ind),lat(ind),'ko')
% Calculate mean of all data points inside box:
zbar = mean(z(ind))

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by