Is there a way to store x,y coordinates from the brush tool in app designer in an app designer edit field (2021b)?

21 Ansichten (letzte 30 Tage)
I have a UI figure in my app with plotted data. With the current version of app designer, I can use the brush tool to obtain x,y coodinates from a point on the plotted data, but I only know how to do this with manual export (to variable, command line, etc.). Is there a way to code a brush tool click (or a button that activates brush tool) that would store the selected x,y values in an edit field in the app?
  2 Kommentare
Kevin Holly
Kevin Holly am 15 Feb. 2022
Bearbeitet: Kevin Holly am 15 Feb. 2022
Below is a semi-automated approach. However, it does not automate the selection of the data nor the exportation of the selected data.
Create scatterplot
scatter(app.UIAxes,rand(20,1),rand(20,1),'g')
hold(app.UIAxes,'on')
scatter(app.UIAxes,(rand(20,1),rand(20,1),'b')
There is a way to active the brush tool programatically. You can use the brush command as shown below:
brush(app.UIAxes,'on')
This would be the same as clicking on the the paintbrush icon (see image below) that shows up in the top right of the axes.
After selecting the datapoint, you can right click and select "Export Brushed..."
Select data you are interested in and select "OK"
Then choose a variable name for your data.
RGB85
RGB85 am 15 Feb. 2022
Kevin, thanks for the response. The "Export Brushed" approach was what I had come up with as well. Is there not a way to programatically access the x,y data of a single point selected with the brush?
I'm trying to select a single point (using the paintbrush tool) and then click a button within the app to grab those x,y values and store them as a variable. I was hoping to use "app.UIAxes.Children.BrushData" but that comes out in uint8.
Any advice?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Kevin Holly
Kevin Holly am 16 Feb. 2022
Try the following to recieve the x and y coordinates.
index = app.UIAxes.Children.BrushData;
xcoord = app.UIAxes.Children.XData(logical(index))
ycoord = app.UIAxes.Children.YData(logical(index))
  3 Kommentare
RGB85
RGB85 am 16 Feb. 2022
As a follow up, how do I clear the values in brush data? I have several buttons that each pick a specific point using the same form of the code you posted. When I move the brush and activate the second button, I get the error:
Intermediate dot '.' indexing produced a comma-separated list with 2 values, but it must produce a single value when followed by subsequent indexing operations.
It seems like I'm accumulating values in the brush data? I'd like to clear it each time after saving the values.
I've tried manually clearing the brush data (right clicking the point and "clear all brushing") and the following code approaches.
cla(app.UIAxes.Children.BrushData);
%%
app.UIAxes.Children.BrushData.cla
%%
app.UIAxes.Children.BrushData = [];
index = [];
Kevin Holly
Kevin Holly am 17 Feb. 2022
Maybe you can make all the BrushData values zero?
app.UIAxes.Children.BrushData = uint8(zeros(size(app.UIAxes.Children.BrushData)));
If you knew the location of the datapoints you wanted to select within the array, you could select the datapoints automatically.
app.UIAxes.Children.BrushData(2)=1; %Let's select the 2nd datapoimt
I created a for loop going through each of the datapoints.
% Run for loop after initially selecting data with brush
for i = 1:length(app.UIAxes.Children.BrushData)
app.UIAxes.Children.BrushData = uint8(zeros(size(app.UIAxes.Children.BrushData)));
app.UIAxes.Children.BrushData(i)=1;
pause(1)
end
After plot/scatterplot is created and assuming only one child for app.UIAxes, you could do the following:
app.UIAxes.Children.BrushData = uint8(zeros(size(app.UIAxes.Children.XData)))
Let's experiment:
for i = 1:length(app.UIAxes.Children.BrushData)
app.UIAxes.Children.BrushData = uint8(zeros(size(app.UIAxes.Children.XData)));
app.UIAxes.Children.BrushData(i)=1;
pause(1)
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

RGB85
RGB85 am 17 Feb. 2022
The end user won't know the location of the data points to select. Essentially, there will be 3 buttons and 3 user-picked points of interest on the same UIAxes plot. The user can select a point, see the x,y coords in an edit field, and see the point visually on the plot. I want to include functionality for the user to be able to reset/repick each point if not satisfied with the first pick. Each button has the following code:
function SelectPointButton_3Pushed(app, event)
index = app.UIAxes1.Children.BrushData;
xcoord = app.UIAxes1.Children.XData(logical(index));
ycoord = app.UIAxes1.Children.YData(logical(index));
app.x1EditField_2.Value = xcoord;
app.y1EditField_2.Value = ycoord;
hold(app.UIAxes1,"on")
plot(app.UIAxes1, app.x1EditField_2.Value,app.y1EditField_2.Value,"Color",'b','Marker','.','MarkerSize',15)
end
When I add the statement to zero BrushData, I'm getting the following errors:
app.UIAxes.Children.BrushData = uint8(zeros(size(app.UIAxes.Children.BrushData)));
Error using size
Dimension argument must be a positive integer scalar or a vector of positive integers.
Error in CalcCc/SelectPointButton_3Pushed (line 182)
app.UIAxes.Children.BrushData = uint8(zeros(size(app.UIAxes.Children.BrushData)));
Error while evaluating Button PrivateButtonPushedFcn.
I'm getting a similar error for "length" using the loop approach. If there's a way to reset all of the values in BrushData to 0, I think that would accomplish my goal. Is there any way I can just delete and/or reintialize brush data? I also tried clearing the whole axes,
cla(app.UIAxes);
and replotting everything. As BrushData is a child of UIAxes, I thought this would also clear BrushData, but it does not.
  4 Kommentare
Kevin Holly
Kevin Holly am 7 Mär. 2022
Please see the app attached. Let me know if this helps. I made the "select point" button, so the coordinates are not drawn until the user selects them after pressing the "Brush" button.
RGB85
RGB85 am 8 Mär. 2022
I've integrated this approach into my code and it works. Thanks for all of your help!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by