From: Mayi DA on
Dear all
As you know, legend(axe_handle, 'legname') can link the relation between legend and axes, I mean that you can get legend handle with the command legend_handle = legend(axe_handle).

However, when copy axes and legend to a new figure, this relationship was lost. Here is an example code to illustrate my statement.
function retchar = test()
close all;
h1 = figure;
ha = subplot(1,1,1);
plot([rand(10,1), rand(10,1)], 'parent', ha);

leg1_handle = legend(ha, {'china'});

h2 = figure;
na = copyobj(ha, h2);
leg2_handle = copyobj(leg1_handle, h2);

retchar = sprintf('1st is: %f, 2nd is: %f', legend(ha), legend(na));
return;

when run: test, you can get:
1st is: 312.003174, 2nd is:

the 2nd is nothing :)

so, my question is how to set relationship between legend and axes?

best regards
mayi
2010-07-18
From: Phil Goddard on

copyobj is somewhat notorious for not actually creating an exact copy of the original object.
Search the Bug Reports for copyobj and you'll see a few of the known limitations.

In this case you can see the incomplete copy by looking at the UserData of the handles,

>> get(leg1_handle,'UserData')
>> get(leg2_handle,'UserData')

You should submit a bug report.

Phil.