MATLAB: Point coordinate markers of selected points

automatic data markers

Hello how can i present automatickly the coordinate data marker of the selected 'or' points? Thanks
plot(x, y, 'g');
hold('on');
index = (5 < y & y < 7);
plot(find(index), y(index), 'or');

Best Answer

Try this:
numPoints = 20;
offset = 0.05; % How much away from the marker the text should be.
x = sort(rand(1, numPoints));
y = 10 * rand(1, numPoints);
plot(x, y, 'g', 'LineWidth', 2);
hold on;
index = (5 < y & y < 7);
plot(x(index), y(index), 'or', 'LineWidth', 2);
grid on;
for k = 1 : length(y)
if index(k)
caption = sprintf('x=%.2f, y=%.2f', x(k), y(k));
text(x(k) + offset, y(k) + offset, caption, 'BackgroundColor', 'y');
end
end