Path: news.mathworks.com!not-for-mail
From: "Jerry" <mricad@yahoo.no000spppam.com>
Newsgroups: comp.soft-sys.matlab
Subject: reorder legend items
Date: Sat, 1 Nov 2008 19:25:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <geiaef$mm1$1@fred.mathworks.com>
References: <gegina$eds$1@fred.mathworks.com> <gegjuo$qko$1@fred.mathworks.com>
Reply-To: "Jerry" <mricad@yahoo.no000spppam.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1225567504 23233 172.30.248.35 (1 Nov 2008 19:25:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 1 Nov 2008 19:25:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 544673
Xref: news.mathworks.com comp.soft-sys.matlab:498441


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

function reorderlegend(newidx,hax)

where hax is the handle of the axes.
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
legend(hgraph(newidx),str(newidx)) to achieve our goal.

"Husam Aldahiyat" <numandina@gmail.com> wrote in message <gegjuo$qko$1@fred.mathworks.com>...
> Sure you can change that by giving each graphic object a handle then using the Legend form
>                     legend(h,'string1','string2',...)
> 
> for example
> 
> h1=plot(a,b)
> h2=findojb('color','g')
> 
> legend([h2, h1],'green plot','something')
>