Using clickableLegend() with Errorbar() for Interactive Data Highlighting and Display

2 views (last 30 days)
I've run into an issue using clickableLegend() which I have found to be very useful for interactively highlighting and displaying data on a single figure. The original version has an error which is addressed in the attached clickableLegend2() script, as described in the discussion section for this function.
I have encountered an error while trying to use clickableLegend() with errorbar() instead of plot():
Here is an example recreating the error, which does not happen when plot() is used instead of errorbar():
clear all;close all;
z = peaks(100);
errorbar(z(:,26:5:50),z(:,26:5:50)*.1)
grid on;
axis manual;
clickableLegend({'Line1','Line2','Line3','Line4','Line5'}, 'Location', 'NorthWest');
----------------
Error Message:
Index exceeds the number of array elements. Index must not exceed 0.
Error in clickableLegend (line 91)
set(objhan(i), 'HitTest', 'on', 'ButtonDownFcn',...
Any Help resolving this would be much appreciated!
Thanks

Accepted Answer

Walter Roberson
Walter Roberson on 18 Oct 2023
For reasons I do not currently understand, when you use the multi-output version of legend() on an errorbar object, no text label is created for it and no icon is created for it. Then the second output of legend() is empty, but the code in clickableLegend2 assumes that there is one line output for each input graphics handle.
The multi-output version of legend has not been documented for some time, and Mathworks has not made any committment to ensure that newer graphics objects will produce compatible outputs with the undocumented facility.
In short... you can no longer use clickableLegend2 with errorbar objects.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!