Is there a way to store x,y coordinates from the brush tool in app designer in an app designer edit field (2021b)?
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
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.
Akzeptierte Antwort
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
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
Weitere Antworten (1)
RGB85
am 17 Feb. 2022
4 Kommentare
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.
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!