Effacer les filtres
Effacer les filtres

find the mean of values which are inside the inpolygon

3 vues (au cours des 30 derniers jours)
pruth
pruth le 29 Oct 2015
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.

Réponse acceptée

Chad Greene
Chad Greene le 1 Nov 2015
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))

Plus de réponses (0)

Catégories

En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by