Need help with Tooltip display?
Show older comments
I have a script that plots CIE Lab values in 3D:

Works great. But as you can see, the tooltip displays the XYZ value.
Instead, I would like it to display the "name of the color".
I asked chatGPT and it suggested the following code:
dcm = datacursormode(gcf);
set(dcm, 'UpdateFcn', @customDataCursor);
function txt = customDataCursor(~, event_obj)
pos = event_obj.Position;
color_name = getColorNameFromRGB(pos, colors);
txt = {['Color: ' color_name]};
end
function color_name = getColorNameFromRGB(rgb, color_struct)
% Implement logic to find the closest color name based on RGB value
% (e.g., Euclidean distance or other methods).
% Return the corresponding color name.
% For simplicity, you can use a lookup table or hard-coded mapping.
% Example:
color_name = 'PamplemousseRose'; % Replace with actual logic
end
I'm kind of lost. Upon initialization of my script, I use the following statements:
T = readtable('SICO Accents de couleur (2023 09 25).xlsx');
colorNames = T(:, 1); % Extract the color names (column 1)
labValues = T(:, 2:4); % Extract the CIE Lab values (columns 2 to 4)
Can I use a command such as "find"?
Accepted Answer
More Answers (0)
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!