How can I tag or label each plotted data point with its sequence number?

조회 수: 24 (최근 30일)
I would like to tag or label each plotted data point, in each line, with its sequence number.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2010년 8월 25일
The following code illustrates how this might be done:
% Create random data
m1 = rand(10,2);
m2 = rand(10,2);
% Calculate label displacement
lbl_dwn = .03*max([m1(:,2) m2(:,2)]);
% Plot data
f = figure;
hold on
plot(m1(:,1), m1(:,2), 'b.-')
plot(m2(:,1), m2(:,2), 'g.-')
% Create an array of sequence numbers (you can use other tags)
s = size(m1);
sequence = 1:s(1);
sequence = num2cell(sequence);
data_labels = cellfun(@num2str, sequence, 'UniformOutput', false);
% Display text
text(m1(:,1), m1(:,2)+lbl_dwn(1), data_labels,...
'Color', 'b',...
'HorizontalAlignment', 'Left')
text(m2(:,1), m2(:,2)+lbl_dwn(2), data_labels,...
'Color', 'g',...
'HorizontalAlignment', 'Left')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series Events에 대해 자세히 알아보기

태그

제품


릴리스

R2006b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by