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

Question about matlab figure legend.

  1. Mar 5, 2009 #1
    Hey folks,

    I need to save a figure from my matlab GUI, which is just a simple plots. Because this plot is the child of a uipanel, so I just use "copyobj" command to copy the handle of the uipanel to the new figure. However, although everything is copied, the legend is not really showing up. I am confused and do not know how to do the setting.

    legend does not have the "Parent" property, so I cannot just do the same setting as the other graphical objects in the plots. Can anyone give me any suggestions on this? Thanks a lot. :-)

    I attached my screen shots here, and you can see the legend is gone...

    Attached Files:

  2. jcsd
  3. Mar 7, 2009 #2


    User Avatar
    Science Advisor

    In this matter, MATLABdude is a MATLABdud.


    EDIT: Legend doesn't have a handle. However, if you pass the string used to generate the first legend in the first plot, you can just recreate it in the second. You probably know this, but you can also make a matrix of strings (a cell array) using the {} braces. For instance:

    >> bowlTeam = {'Fred', 'Tammy', 'Joe'};

    Using bowlTeam{3} returns Joe. I believe bowlTeam(3) returns either an e, or is a syntax error. Mathworks documentation page on cell arrays:
    Last edited: Mar 8, 2009
  4. Mar 8, 2009 #3
    Thank you very much. I just tried to get that axes object, and recreate the legend. It works well. :-)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook