Filter löschen
Filter löschen

find the mean of values which are inside the inpolygon

3 Ansichten (letzte 30 Tage)
pruth
pruth am 29 Okt. 2015
Beantwortet: Chad Greene am 1 Nov. 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.

Akzeptierte Antwort

Chad Greene
Chad Greene am 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))

Weitere Antworten (0)

Kategorien

Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by