Data Grids as Logical Variables

You can apply logical criteria to numeric data grids to create logical grids. Logical grids are data grids consisting entirely of 1s and 0s. You can create them by performing logical tests on data grid variables. The resulting binary grid is the same size as the original grid(s) and can use the same referencing vector, as the following hypothetical data operation illustrates:

logicalgrid = (realgrid > 0);

This transforms all values greater than 0 into 1s and all other values to 0s. You can apply multiple conditions to a grid in one operation:

logicalgrid = (realgrid >- 100)&(realgrid < 100);

If several grids are the same size and share the same referencing vector (i.e., the grids are co-registered), you can create a logical grid by testing joint conditions, treating the individual data grids as map layers:

logicalgrid = (population > 10000)&(elevation < 400)&...
              (country == nigeria);

Several Mapping Toolbox™ functions enable the creation of logical grids using logical and relational operators. Grids resulting from such operations contain logical rather than numeric values (which reduce storage by a factor of 8), but might need to be cast to double in order to be used in certain functions. Use the onem and zerom functions to create grids of all 1s and all 0s.

To see an example, view Determine Area Occupied by Logical Grid Variable.