Main Content

changem

Replace values in array

    Description

    B = changem(A,new) replaces all occurrences of 0 in array A with the specified scalar new. This function is useful for replacing values in classification grids.

    B = changem(A,new,old) replaces all occurrences of old with new.

    example

    Examples

    collapse all

    Read a land cover classification of Oahu, Hawaii as an array, a map cells reference object, and a colormap. The elements of the array index into the colormap.

    [A,R,cmap] = readgeoraster("oahu_landcover.img");

    Deciduous forest, evergreen forest, and mixed forest are indicated by the values 9, 10, and 11 in the array, respectively. Create an array that uses the same color for all forests by replacing occurrences of 9 and 10 with 11.

    new = [11 11];
    old = [9 10];
    B = changem(A,new,old);

    Display the old and new land cover classifications.

    figure
    mapshow(A,cmap,R)
    title("Land Cover Classification with Three Forest Types")

    Figure contains an axes object. The axes object with title Land Cover Classification with Three Forest Types contains an object of type image.

    figure
    mapshow(B,cmap,R)
    title("Land Cover Classification with One Forest Type")

    Figure contains an axes object. The axes object with title Land Cover Classification with One Forest Type contains an object of type image.

    Input Arguments

    collapse all

    Input array.

    New value, specified as a scalar or vector. When new and old are vectors, the function replaces occurrences of old(k) with new(k).

    The size of new must match the size of old.

    Value to replace, specified as a scalar or vector. When new and old are vectors, the function replaces occurrences of old(k) with new(k).

    The size of new must match the size of old.

    Version History

    Introduced before R2006a

    See Also

    Functions