From: lily on
Hi,
I don't know exactly about command legend and its object_handle property,I have some questions in the following example. Thanks a lot.

clf;clc;
x = -pi:pi/20:pi;
h1=plot(x,sin(x));
hold on;
ix=randperm(numel(x));
ix=ix(1:10);
y=sin(x);
line(x(ix),y(ix),...
'marker',mkn,...
'markersize',10,...
'markerfacecolor',[1,1,0],...
'linestyle','none');
str='sin_x';
lh = legend(h1,str,2);
set(lh,'Interpreter','none');

%% add point [x(ix),y(ix)] in the curve.
ch=findall(lh,'type','line');
%::::::::::::::::::::::::question1
% ch(1) and ch(2) represent what?
xp=get(ch,'xdata');
xp=xp{1};
yp=get(ch,'ydata');
yp=yp{1};
line(xp,yp,...
'parent',lh,...
'marker',mkn,...
'markersize',10,...
'markerfacecolor',[1,1,0],...
'linestyle','none');
hold on;
%%

[legh1,objh1,ploth1,textstrs1]=legend;
set(objh1(1),'string','teststring');
set(objh1(2),'color','g');
set(objh1(3),'color','r');
%::::::::::::::::::::::::question2
%how to change the symbol * into red? And what does objh1(3) represent?

h2=plot(x,cos(x),'-ro');
newstr='cos_x';
lh = legend([h1;h2],str,newstr,2);
%::::::::::::::::::::::::question3
%after update the legend,the symbol * disappears.
%if first plot(x,cos(x),'-ro'),then plot(x,sin(x)) and added points [x(ix),y(ix)],
%the symbol o of legend still remains,why?
%::::::::::::::::::::::::question4
%any easier method to add new contents in a legend?or add multi-legend for one %image?

[legh,objh2,ploth,textstrs]=legend;
set(lh,'Interpreter','none');
set(objh2(6),'color','g');