This error can occur if the regular data grid referenced in the worldfile is in some projected coordinate system, and not a geographic (latitude-longitude) system. GRADIENTM is not applicable in this case. Instead, you should use the GRADIENT function, which is part of base MATLAB:
and scale the first return value by R(2,1) - the width of a raster cell in the x-direction -- and the second by R(1,2) --the (signed) height of a raster cell in the y-direction.
dx = dx / R(2,1);
dy = dy / R(1,2);
This will convert the gradient arrays from change per column or row to change per x and y in the projected system.
For more information on the GRADIENT function, execute the following in the MATLAB command prompt:
Best Answer