findm
Latitudes and longitudes of nonzero data grid elements
Syntax
[lat,lon] = findm(Z,R)
[lat,lon] = findm(latz,lonz,Z)
[lat,lon,val] = findm(...)
mat = findm(...)
Description
[lat,lon] = findm(Z,R)
computes the latitudes and longitudes of the nonzero elements of a regular data grid,Z
.R
can be a geographic raster reference object, a referencing vector, or a referencing matrix.
IfR
is a geographic raster reference object, itsRasterSize
property must be consistent withsize(Z)
.
IfR
is a referencing vector, it must be a 1-by-3 with elements:
[cells/degree northern_latitude_limit western_longitude_limit]
IfR
is a referencing matrix, it must be 3-by-2 and transform raster row and column indices to or from geographic coordinates according to:
[lon lat] = [row col 1] * R
IfR
是一个引用矩阵,它必须定义一个(non-rot吗ational, non-skewed) relationship in which each column of the data grid falls along a meridian and each row falls along a parallel. Nearest-neighbor interpolation is used by default. NaN is returned for points outside the grid limits or for whichlat
orlon
contain NaN. All angles are in units of degrees.
[lat,lon] = findm(latz,lonz,Z)
returns the latitudes and longitudes of the nonzero elements of a geolocated data gridZ
, which is an M-by-N logical or numeric array. Typicallylatz
andlonz
are M-by-N latitude-longitude arrays, butlatz
may be a latitude vector of length M andlonz
may be a longitude vector of length N.
[lat,lon,val] = findm(...)
returns the values of the nonzero elements ofZ
, in addition to their locations.
mat = findm(...)
returns a single output, wheremat = [lat lon]
.
This function works in two modes: with a regular data grid and with a geolocated data grid.
Examples
The data grid can be the result of a logical operation. For example, load elevation raster data and a geographic cells reference object. Then, find all locations with elevations greater than 5500 meters.
loadtopo60c[lat,lon] = findm((topo60c > 5500),topo60cR); [lat lon]
ans = 34.5000 79.5000 34.5000 80.5000 30.5000 84.5000 28.5000 86.5000
These points are in the Himalayas. Find the grid values at these locations using thegeographicToDiscrete
andsub2ind
functions.
[row,col] = geographicToDiscrete(topo60cR,lat,lon); indx = sub2ind(size(topo60c),row,col); heights = topo60c(indx)
heights = 5559 5515 5523 5731