How can i save the brushed data to a variable?

90 ビュー (過去 30 日間)
Rifat Tolga KIRAN
Rifat Tolga KIRAN 2012 年 1 月 8 日
コメント済み: stephen brewis 2018 年 12 月 24 日
I am working on a program which includes brushing datas on a plot. Supposing that we have a script like this:
h = brush;
what kind of a function should i write to retrieve 'GetSeletedData'?
and i want to get the selected data in a variable. What should i do? i am researhing this issue for 2 days but i couldnt catch a clue. Thank you for your interests.
  2 件のコメント
stephen brewis
stephen brewis 2018 年 12 月 24 日
I am not a programmer but hope you find this usefull. !!! Make sure you BRUSH the same number of points from both plots
function brushTest()
hold on
function brushedDataCallback(~,~)
clear lineBrushed
for i=1:size(h)
clear x


回答 (7 件)

Walter Roberson
Walter Roberson 2012 年 1 月 8 日
In your previous thread, I gave you a link to a routine that find the brushed objects.
As hinted in the code referenced, for any one object that has been brushed, get() the Brushdata property; it will be a logical vector, where true indicates that the corresponding datapoint has been brushed. (Or so it appears to me.)
xd = get(Handle, 'XData');
yd = get(Handle, 'YData');
brush = get(Handle, 'BrushData');
brushed_x = xd(brush);
brushed_y = yd(brush);
Or if you prefer indices,
brushed_locs = find(get(Handle, 'BrushData'));
  3 件のコメント
Ross 2015 年 10 月 21 日
to answer Rifat Tolga KIRAN by slightly changing the above example for when using from the matlab console:
ax1 = plot(rand(50,1));
%then select the brushing tool either with a console command or via the figure menu, select your data.
I added conversion to logical datatype so that it can be used to as an index for the xd and yd arrays.
brush = logical(get(ax1, 'BrushData'));
xd = get(ax1, 'XData');
yd = get(ax1, 'YData');
brushed_x = xd(brush);
brushed_y = yd(brush);


Rifat Tolga KIRAN
Rifat Tolga KIRAN 2012 年 1 月 9 日
h = brush;
set(h,'Color',[1 0 0],'Enable','on','ActionPostCallback',@GetSelectedData);
Handle = findobj(gcf,'-property','BrushData');
brushed_locs = find(get(Handle, 'BrushData'));
When i use like this it gives me an error like,
Undefined function 'find' for input arguments of type 'cell'.
Error in nakamura (line 94)
brushed_locs = find(get(Handle, 'BrushData'));
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 1 月 9 日
brushed_locs = cellfun(@find, get(Handle, 'BrushData'), 'Uniform', 0);


Rifat Tolga KIRAN
Rifat Tolga KIRAN 2012 年 1 月 9 日
And if also fire the @GetSelectedData function in the postcallback, even if i write simple fprintf in the function i get following errors:
Warning: An error occurred during the mode callback.
> In uitools.uimode.fireActionPostCallback at 14
In datamanager.brushup at 114
In brush>@(es,ed)datamanager.brushup(es,ed)
In hgfeval at 63
In uitools.uimode.modeWindowButtonUpFcn at 46
In uitools.uimode.modeControl>localModeWindowButtonUpFcn at 155
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 1 月 9 日
What is your function declaration for GetSelectedData ? If it does not have two arguments, it would fail.


Rifat Tolga KIRAN
Rifat Tolga KIRAN 2012 年 1 月 11 日
Here is my GetSelectedData:
function [SelectedData] = GetSelectedData(es,ed)
fprintf('Obje üzerinden veri seçimi tamamlandı!\n');
Handle = findobj(gcf,'-property','BrushData');
a = get(Handle,'BrushData')
When i add two variables into the input segment the errors has gone but now i have a problem with variables that are not global to usage. I cant see the SelectedData variable in the main program.
  2 件のコメント
Walter Roberson
Walter Roberson 2012 年 1 月 11 日
Also, remember that your findobj() is going to be returning the handles of everything in your figure that has the BrushData property, and when you get() on multiple handles then a cell array will be returned by get() .
Your code shows assigning to "a" but does not show you creating SelectedData .


Rifat Tolga KIRAN
Rifat Tolga KIRAN 2012 年 1 月 12 日
i have tried to find every handles' properties including 'BrushData' but none of them has a tag like this. But my function returns data which is fulled with zeros and one of which shows the selected and nonselected indices. let me share the program and maybe you can help me by that way.

Jesse Salazar
Jesse Salazar 2015 年 1 月 14 日
You want to execute the following:
hBrushing = findall(gca,'tag','Brushing');
brushData = get(hBrushing, {'Xdata','Ydata'});
brushIdx = ~isnan(brushData{1}); % Puts a '1' at indices that aren't NAN
brushXData = brushData{1}(brushIdx);
brushYData = brushData{2}(brushIdx);
Note that gca can be replaced with the handle to your axes, such as:
hFig = figure; hAxes = axes(hFig);
And if you need the vector indices of the brushData within the line:
brushVecIdx = find(brushIdx)
Not sure I have seen the "BrushData" tag, mentioned in a previous answer.

Udo Schröder
Udo Schröder 2018 年 11 月 14 日
I think the problem is up to now not solved. So I have the same issue.
I want to use the Brush/Select Data tool from a plot window to mark data. This data (or index) should then be automatically transferred into a variable in the workspace.
The figure object does not have any property like "BrushData" or something similar. I am working with R2018b.
Can anyone help?
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 11 月 15 日
Figure objects are not brushable. Some kinds of individual graphics objects are brushable.
no longer works in HG2. BrushData is an undocumented property, and apparently now you cannot findobj() -property with an undocumented property. The most efficient workaround I know at the moment is
figure_handles = findall(gcf); Handles = figure_handles( arrayfun(@(H) isprop(H, 'BrushData'), figure_handles) );
after which Handles contains the handles of all of the potentially brushable objects. After that you can do something like
info = [num2cell(Handles),arrayfun(@(H) find(H.BrushData), Handles, 'uniform', 0)];
This will give you a cell array in which the first column is graphic objects and the second column is a vector of corresponding brushed indices. You cannot simply use a vector of indices because it is common to have more than one brushable graphics object in a plot and you need to have context for the indices.



Find more on Graphics Object Identification in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by