find the mean of values which are inside the inpolygon

2 visualizaciones (últimos 30 días)
pruth
pruth el 29 de Oct. de 2015
Respondida: Chad Greene el 1 de Nov. de 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.

Respuesta aceptada

Chad Greene
Chad Greene el 1 de Nov. de 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))

Más respuestas (0)

Categorías

Más información sobre Mapping Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by