Mapping Toolbox | ![]() ![]() |
Convert x- and y-coordinates to row and column indices
Syntax
Description
[rowgrat,colgrat] = yx2rc(ygrat,xgrat,y1,x1,yperrow,xpercol) computes row and column indices from y- and x-coordinates. ygrat
and xgrat
are the Cartesian coordinates for a grid with the upper left corner at coordinates x1
and y1
. yperrow
and xpercol
are the y- and x-increment per row and column. The outputs rowgrat
and colgrat
correspond to matrix locations ygrat
and xgrat
.
Examples
[ygrat,xgrat] = meshgrat(1000:-500:0,-1000:500:0) ygrat = 1000 1000 1000 500 500 500 0 0 0 xgrat = -1000 -500 0 -1000 -500 0 -1000 -500 0 x1 = -1000; y1 = 1000; yperrow = -500; xpercol = 500; [rowgrat,colgrat] = yx2rc(ygrat,xgrat,y1,x1,yperrow,xpercol) rowgrat = 1 1 1 2 2 2 3 3 3 colgrat = 1 2 3 1 2 3 1 2 3
Remarks
This function is used for one step in the process of extracting projected matrix data from a file. The process generally consists of the following steps: 1) define the map projection as described in the data source documentation, 2) map desired geographic limits into projected coordinates using mfwdtran
, 3) use yx2rc
to determine associated row and column limits in the stored matrix, 4) extract sub-matrix using readmtx
, 5) convert graticule of row and column indices to projected x and y coordinates using rc2yx
, 6) convert x and y to geographic graticule using minvtran
.
See Also
rc2yx |
Row and column indices to x- and y-coordinates |
readmtx |
Read a matrix stored in a file |
![]() | worldmap | zdatam | ![]() |