MATLAB: Can MATLAB legend color order be changed as the legend element order changes

colorlegendMATLABorder

Using the following code from the 'Specify Legend Descriptions During Line Creation' example in MATLAB help, I've created the following plot:
I've successfully changed the order of the legends entries using the following steps:
1. Clicked the arrow button so I could select the legend
2. Double clicked on the legend
3. Selected More Properties from the property editor
4. Selected the 'String' property and re-ordered the elements of the legend
The order of the legend elements did change. However, the associated color scheme did not.
Is there a separate function for this? Can the color order be changed as well?
Thanks.

Best Answer

I got lost at this step:
4. Selected the 'String' property and re-ordered the elements of the legend
I don't think that there's anything in the editor for the String property which lets you re-order the elements of the legend.
Perhaps you just changed the edited the strings without changing the order? To actually change the order of the entries, you probably want to do something like this:
legend([p2 p3 p1])
or even
p = [p1 p2 p3];
for i=1:100
legend(p(randperm(3)))
drawnow
end