How do I identify and display a single line in a multi-line plot?

3 views (last 30 days)
I'm trying to pick out a single line in a multi-line plot. I can highlight a line and its corresponding legend item, but I'd also like to display the name of the line on the plot when the line is clicked. I've tried tooltips and the data cursor so far. Below is a simple test case:
% code
y = plot(1:0.5:3, rand(5,5));
n = length(1:0.5:3);
a = zeros(n,1);
for i = 1:n
set(y(i), 'ButtonDownFcn', {@LineSelected, y});
a(i,1) = i;
end
a = num2str(a);
legend(a)
% code
function LineSelected(ObjectH, EventData, h)
set(ObjectH, 'LineWidth', 2.5);
set(h(h ~= ObjectH), 'LineWidth', 0.5);
end

Answers (0)

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!