sortx

Sorts the columns of a heatmap by the values in one of its rows.

Category: Graphics > 2-D and 3-D Plots

Syntax

sortx(h)

Sorts the columns by the first displayed row, in ascending order.

sortx(h, row)

Sorts by the row named row.

sortx(h, row, direction)

Chooses 'ascend' or 'descend' order.

Description

Only the display order changes: the heatmap's XDisplayData and ColorDisplayData properties are rearranged, and the original data stays the same. The sort is stable, so ties keep their relative order, and missing values go last.

Input arguments

h
Handle of a heatmap chart.
row
Label of the row to sort by, as it appears in YDisplayData.
direction
'ascend' (default) or 'descend'.

Example

Reordering columns

hm = heatmap([3 1 2; 6 4 5]);
sortx(hm, '1');
disp(hm.XDisplayData')
disp(hm.ColorDisplayData)
Output
    {'2'}    {'3'}    {'1'}
     1     2     3
     4     5     6

See also

sorty heatmap sort sortrows