Create a callback that waits for the brush to include some data and then display them

5 次查看(过去 30 天)
I have the following simple example:
x=-4:0.1:4;
y= x.^2-1;
f=figure;
h=plot( x, y );
bO = brush(gcf);
set(bO,'enable','on');
data=logical(get(h,'brushdata'));
disp(data)
If I run it all the data will be zero. If I run it until the set command, choose subsequently the data from the plot and then continue with executing the other two commands the selected data will be displayed.
How can I control with the callback to wait until I gather the data and then display them?

采纳的回答

Giorgos Papakonstantinou
After trying a lot I and taking into account a gui that I had done in the past I managed to do more or less what I wanted.
Here is the script in which I plot the data and from which I want to extract some brushed data:
x=-4:0.1:4;
y= x.^2-1;
f=figure;
h=plot( x, y );
STR={'Press close button when finishing with selection'};
out=brushpanel(STR,f);
and here is the brushpanel function that I made. It returns the selected data from the brush and enables off the brush.
function out=brushpanel(STR,fighandle)
g.fh = figure('units','pixels',...
'position',[1169 324 380 100],...
'menubar','none',...
'Color','w',...
'name','Select plot regions',...
'numbertitle','off',...
'resize','off');
g.sub=annotation('textbox',...
'units','pixels',...
'position',[0 0 380 100],...
'Tag','box',...
'Color',[58 51 153]/255,...
'BackgroundColor','none',...
'String',STR,...
'Fontsize',14,...
'FaceAlpha',0,...
'EdgeColor', [112 112 112]/255);
g.bg = uibuttongroup('units','pix',...
'pos',[0 0 380 50],...
'BorderType','line',...
'ForegroundColor','w');
g.rd = uicontrol(g.bg,...
'style','push',...
'unit','pix',...
'position',[260 15 70 22],...
'Fontsize',8,...
'string','Close');
g.bO = brush(fighandle);
g.axhandle=get(fighandle,'CurrentAxes');
set(g.bO,'enable','on');
set(g.rd(:),'callback',{@select,g});
uiwait(g.fh)
hBrushLine = findall(g.axhandle,'tag','Brushing');
brushedData = get(hBrushLine, {'Xdata','Ydata'});
brushedIdx = ~isnan(brushedData{1});
brushedXData = brushedData{1}(brushedIdx);
brushedYData = brushedData{2}(brushedIdx);
out=[brushedXData' brushedYData'];
close(g.fh)
function select(varargin)
g = varargin{3};
str=get(g.rd(1),'val');
if str(1)==1
g.st=true;
set(g.bO,'enable','off');
end
guidata(g.fh,g.bO);
uiresume
I would appreciate the contributors' useful comments. The answer that I provided above covers my needs to a certain extend. I just posted it here with the intention of providing a solution to other people that might have a similar question as me. Thanks

更多回答(2 个)

Giorgos Papakonstantinou
I would kindly ask you to help me on this matter cause I need to gather data from the plot and remove them. I have made certain measurements and I need to discard some data because they are faulty. Maybe in the past had a similar problem like me. But I haven't found anything similar in the Answers. If you know how to solve or you can redirect me to similar question I would be grateful
regards, Giorgos
  2 个评论
Jan
Jan 2013-6-19
Please do not bump your question after a short period of time. The contributors of this forum answer, when they find the time and know a solution. If the question is bumped to the top without really new informations, reading it another time wastes the time of the voluntary helpers.
Please use the answer section for answers only. Comments about the question are better inside the comment section of the question. Thanks.
Giorgos Papakonstantinou
I am sorry Jan. It wasn't my intention to waste anyone's time. Especially of the contributors who have helped more than enough. The only thing that I wanted was some guidance or direction for a thing that takes me lots of hours without leading me anywhere and which I believe that would be easy task for somebody expert. But I was wrong. Sorry again about "stealing" your time.

请先登录,再进行评论。


Andrew Fairgrieve
Andrew Fairgrieve 2021-10-1
Its not a pretty solution but it seems to work:
b=brush;
b.Enable = 'on';
waitfor(b,'Enable','off')
This will cause the script to wait for the user to turn off the brush, before continuing with the rest of the script. If the user has used the brush to delete points,
~isnan(PlotHandle.YData)
, can then be used to identify data the user has deleted and then this can be applied to related data in the script.

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by