MATLAB Custom Legend Code Example
Example 1: add manual legend matlab
h1=plot([1:10],'Color','r','DisplayName','This one');hold on; h2=plot([1:2:10],'Color','b','DisplayName','This two'); h3=plot([1:3:10],'Color','k','DisplayName','This three'); legend([h1 h3],{'Legend 1','Legend 3'})
Example 2: automatic legend matlab
str = {strcat('z = ' , num2str(z))} % at the end of first loop, z being loop output str = [str , strcat('z = ' , num2str(z))] % after 2nd loop % plot your data legend(str{:})
Comments
Post a Comment