MATLAB: How to specify the legend to inherit the colors of the arrows in the figure in MATLAB 7.0.1 (R14SP1)

annotation;arrow2leglegendMATLAB

I am using the ANNOTATION function to make my plot and set different colors for each arrow. I would like to be able to set a legend for each of these arrows since LEGEND does not automatically detect the colors from the arrows in the figure.

Best Answer

LEGEND cannot be used to directly detect arrows in your plot because arrows are annotation objects and not actual plots in the figure.
To work around this issue, you can create a dummy line of the same color as the arrow and set its visibility to off. LEGEND will then detect this line object and display a legend of the appropriate color. For example,
annotation('arrow',[0.25,0.5],[0.5,0.5],'color','red')
lh = line(1:3,1:3,'color','r','visible','off')
legend('mylegend')