Is there a way to store x,y coordinates from the brush tool in app designer in an app designer edit field (2021b)?
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
RGB85
el 14 de Feb. de 2022
Comentada: RGB85
el 8 de Mzo. de 2022
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 comentarios
Kevin Holly
el 15 de Feb. de 2022
Editada: Kevin Holly
el 15 de Feb. de 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.
Respuesta aceptada
Kevin Holly
el 16 de Feb. de 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 comentarios
Kevin Holly
el 17 de Feb. de 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
Más respuestas (1)
RGB85
el 17 de Feb. de 2022
4 comentarios
Kevin Holly
el 7 de Mzo. de 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.
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!