1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| x = 1:7;
N = 5;
figure
hold on
for n=1:N
p(n) = plot(x,rand(1,7)+n-1);
end
set(p,'color','b');
% Modification
hold on
for n=1:N
x = get(p(n),'xdata');
y = get(p(n),'ydata');
text(x(2),y(2),num2str(n))
end
hl = legend(p,strcat('Y',num2str((1:N).')));
h = get(hl,'children');
delete(h(2:3:end))
h(2:3:end)=[];
for n=1:2:numel(h)
x = get(h(n),'xdata');
y = get(h(n),'ydata');
str = sprintf('%d : ',numel(h)/2-(n-1)/2);
text(x,y,str,'hor','center', ...
'units','normalized', ...
'parent',hl)
delete(h(n));
end
h(1:2:end)=[]; |
Partager