Is the brush tool still supported in R2017b, programatically?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to find the best way for a user to interactively select a subset of data in a scatter plot that will then be polyfit and otherwise analyzed. I've been trying to use the brush tool, which allows the user to draw a box of the data of interest. It seems like much of the implementation is entirely interactive and handled by the matlab graphics under the hood. I would really like a way to pull the selected data out of the brush object.
I found these previous documents from 2012 and 2015 that claim to have solved the problem but the solution is not working for me:
The second article seems to suggest that the styles and data drawn on the graph by brushing are added as a new Child of the brushed axes. This doesn't appear to be the case anymore. Perhaps if I could find where this scatter plot style is stored, I could tap into the data. I understand that it is difficult to get a callback to return data to the user, so I guess I'll also need a way to detect when the data brushing is changed.
0 commentaires
Réponse acceptée
Amy
le 27 Oct 2017
Hi Henry,
It's possible to save brushed data as a workspace variable by right clicking and selecting 'Create Variable'.
I think that maybe what you are asking for instead is a way to save the data automatically as soon as you select the data with the brush tool? There are a few ways to do this in R2017b.
Some people have written their own functions for doing this as well - have you checked this File Exchange submission, for example?
The way I would suggest doing this would be to use the 'BrushData' property of a brush-able graphics object in conjunction with the data brush tool's 'ActionPostCallback' property. You can save data to the workspace using the assignin function in the callback. I think this is what you mean by returning data to the user.
You'd want to assign the callback using syntax similar to this (where hFig is the handle to the current figure and onBrushAction is a function you would define):
hBr = brush(hFig);
hBr.ActionPostCallback = {@onBrushAction};
The data drawn on the graph are saved in the children property of the axes. Your callback function would probably want to loop through all these children objects. You could first check each object to see if it has a 'BrushData' property using isprop and then, if it does, use that property as a logical index into the XData and YData properties to gather the brushed data itself. Then your callback function could call 'assignin' to save that data as a variable in your base workspace.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Object Programming dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!