Selecting points from UIAxes App Designer MATLAB R2022a and get rgb data and x,y coordinates

28 views (last 30 days)
Don't know how to get data when I select point from UIAxes.
Is it right to use UIAxesButtondown function to use it?
Or do I have to use WindowButtondown function?
If there's a way to know the rgb data and x,y coordinate by clicking the image. Please let me know.
Thank you.

Accepted Answer

Pulkit
Pulkit on 17 Nov 2022
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)
>>
>> % ~ Currently not used (empty)
>> % event_obj Object containing event data structure
>> % output Data cursor output
>>
>> rData = vecnorm([event_obj.Target.XData; event_obj.Target.YData]);
>> [~,i] = min(abs(norm(event_obj.Position) - rData));
>> output = event_obj.Target.CData(i);
>>
>> end
  • 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.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer 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!