According to my understanding you want read color values of a chart using the data cursor on a UIAxes.
Each point in charts has an associated value represented by its color. When using the data cursor, the box that appears next to the cursor shows the X and Y values of the corresponding point. If you want to see the value associated with the color of that point. This can be achieved by following the steps below:
- Create a Start Up function for the UIFigure
- In the Start Up function, please include the following code:
>> d = datacursormode(app.UIFigure);
>> d.UpdateFcn = @showValue;
>> function output = showValue(~,event_obj)
>> rData = vecnorm([event_obj.Target.XData; event_obj.Target.YData]);
>> [~,i] = min(abs(norm(event_obj.Position) - rData));
>> output = event_obj.Target.CData(i);
- Run the app, and check if the expected outcome is achieved
The code snippet above operates on the data cursor. On the first line, it queries the object and saves it with the name "d". Then, it assigns ‘showValue’ as the function to execute when the data cursor is updated. In ‘showValue’, the Target of event_obj is the Scatter object, whose fields include XData, YData and CData. event_obj.Position is the (X,Y) position of the cursor on the UIAxes.
The algorithm inside this function calculates the distance of each scatter point from the origin (rData), and compares it to the distance from the origin of the selected scatter point. Then, it finds the index at which the values match (i). Finally, it assigns the output (i.e., what appears in the box near the cursor) as the CData value of the scatter point determined by index i.