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

3 visualizaciones (últimos 30 días)
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

Respuestas (0)

Categorías

Más información sobre Language Fundamentals en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by