Is there a way to store x,y coordinates from the brush tool in app designer in an app designer edit field (2021b)?
24 次查看(过去 30 天)
显示 更早的评论
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 个评论
Kevin Holly
2022-2-15
编辑:Kevin Holly
2022-2-15
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.
采纳的回答
Kevin Holly
2022-2-16
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 个评论
Kevin Holly
2022-2-17
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
更多回答(1 个)
RGB85
2022-2-17
4 个评论
Kevin Holly
2022-3-7
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!