<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238515</link>
    <title>MATLAB Central Newsreader - reorder legend items</title>
    <description>Feed for thread: reorder legend items</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 01 Nov 2008 03:34:02 -0400</pubDate>
      <title>reorder legend items</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238515#608457</link>
      <author>Jerry </author>
      <description>figure;&lt;br&gt;
plot(0:10,0:10,'rx-',0:10,10:-1:0,'go--');&lt;br&gt;
legend('cross','circle');&lt;br&gt;
&lt;br&gt;
the order of the legend items depends on the oder of plotting, i.e., in the example above, it will be &quot;rx- cross&quot; on the top. Is there any way to switch the order without re-plot? switching the string is not hard, but I didn't figure out how to switch the whole thing, e.g., make &quot;go-- circle&quot; on the top. This is useful, for example, after you create a figure with a legend of many items, then for some reason, you want to change the order of the legend. (the order of plotting may be ad hoc, but you want your legend follow some rule). &lt;br&gt;
&lt;br&gt;
Thanks.</description>
    </item>
    <item>
      <pubDate>Sat, 01 Nov 2008 03:55:04 -0400</pubDate>
      <title>reorder legend items</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238515#608460</link>
      <author>Husam Aldahiyat</author>
      <description>Sure you can change that by giving each graphic object a handle then using the Legend form&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;legend(h,'string1','string2',...)&lt;br&gt;
&lt;br&gt;
for example&lt;br&gt;
&lt;br&gt;
h1=plot(a,b)&lt;br&gt;
h2=findojb('color','g')&lt;br&gt;
&lt;br&gt;
legend([h2, h1],'green plot','something')</description>
    </item>
    <item>
      <pubDate>Sat, 01 Nov 2008 19:25:04 -0400</pubDate>
      <title>reorder legend items</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238515#608519</link>
      <author>Jerry </author>
      <description>it's easy to get the string in the legend box. however, it's difficult to get their corresponding handles of the graphy objects they represent without specifying some particular properties of the graph object in findobj. I'm trying to write a function like this&lt;br&gt;
&lt;br&gt;
function reorderlegend(newidx,hax)&lt;br&gt;
&lt;br&gt;
where hax is the handle of the axes.&lt;br&gt;
if there are five graph objects in the axes, by newidx=[2 1 4 3 5], we'll be able to switch items 1 and 2, and switch items 3 and 4 in the legend box. if we can get the handles of the graph objects (hgraph) that the legend strings represent, we can use&lt;br&gt;
legend(hgraph(newidx),str(newidx)) to achieve our goal.&lt;br&gt;
&lt;br&gt;
&quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; wrote in message &amp;lt;gegjuo$qko$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Sure you can change that by giving each graphic object a handle then using the Legend form&lt;br&gt;
&amp;gt;                     legend(h,'string1','string2',...)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for example&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; h1=plot(a,b)&lt;br&gt;
&amp;gt; h2=findojb('color','g')&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; legend([h2, h1],'green plot','something')&lt;br&gt;
&amp;gt; </description>
    </item>
  </channel>
</rss>

