find the mean of values which are inside the inpolygon
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mapping Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!