Re-orders the legend entries (without modifying the actual order the curves are stacked on the axes)
order - an array specifying the order of legend entries
h - axis handle (optional, defaults to current axis)
Invoking the function without an argument or with order==[] causes the labels of the curves to be returned (or displayed, if nargout==0).
e.g.
>> x = 0:.1:10;
>> plot(x,x,x,2*x,x,3*x,x,4*x); legend('x','2x','3x','4x');
>> reorderLegend
[1] 4x
[2] 3x
[3] 2x
[4] x
The indices of the labels (i.e., 1 to 4 in the above e.g.)can be used to specify the desired order of legend entries.
e.g. >> reorderLegend([4,2,1,3]); % legend: 'x','3x','4x','2x' (from top to bottom)
Notes:
- By default, the legend entries are in the reverse order of the indices (because the curves are in a stack).
- `reorderLegend' doesn't change the order of the curves (i.e., the indices are not changed when it's called).
Cite As
Damith Senaratne (2026). reorderLegend (https://www.mathworks.com/matlabcentral/fileexchange/37265-reorderlegend), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 |
