Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Dynamic Legend in MatLab

  1. Nov 28, 2011 #1
    Hello,

    I am trying to do the following:

    for i=1:3
    semilogy(plot1,'r(-,:,d)',plot2,'b(-,:,d)',plot3,'k(-,:,d)');
    legend('i legend1','i legend2',''i legend1'')
    end

    where I need to draw the same plots under different settings, such that each function has the same color under the different settings, but with different style, e.g: solid line in the first, dotted in the second, ... and so on. I also want to include the number i in the legend at each iteration. How to do that?

    Thanks
     
  2. jcsd
  3. Dec 2, 2011 #2
  4. Dec 2, 2011 #3

    jhae2.718

    User Avatar
    Gold Member

  5. Dec 2, 2011 #4

    jhae2.718

    User Avatar
    Gold Member

    Actually, if I'm understanding what you want to do, I think you could get away with using sprintf and format statements as inputs to the legend and semilogy functions.

    Something like:
    Code (Text):

    legend(sprintf('%i legend 1', i), sprintf('%i legend 2', i), sprintf('%i legend 1', i))
     
    It's not pretty but it should work. You can do something similar for the line types with a cell array.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Similar Discussions: Dynamic Legend in MatLab
  1. Matlab Legend Problem (Replies: 0)

Loading...