MATLAB: Legend on a plot. legend Hi All, I Plot a 250×10 matrix. But I only want the legend for the 3rd 5th and 9th element. How can I do this? Best Answer Use the handle explicitly:h = plot(cumsum(rand(250,10)));legend(h([3 5 9]),'third','fifth','ninth')And for more info:doc legend Related SolutionsMATLAB: How to add legends You can also use the following:hold on %after the first plot to continue plotting on the same figurelegend on% or legend('plot1','plot2','plot3'); MATLAB: How to hold legend Look at this Examplet=0:0.1:10;y1=sin(t);y2=cos(t);% ------Plot the first data----------plot(t,y1);h=legend('word1')%-------Plot the second data---------hold onplot(t,y2);str=get(h,'string')% get the previous legendnew_leg='word2' % your new legendh=legend([str new_leg]) % concatenate the new and the previous legend Related QuestionLegendHow to label 2nd y-axisLegendGet lineseries handlePlot Legend‘legend’ problem
Best Answer