Plot a signal, manually brush data range, and generate new variable

8 views (last 30 days)
I am looking for a means to plot a signal, and have the brush function automatically on. Manually select that data range (mostly the peaks), and then automatically create a new variable (with a predefined name).
I am trying to cut out the select brush data, then right-click the data, select create new variable and type in the new name.

Answers (1)

Ramnarayan Krishnamurthy
Ramnarayan Krishnamurthy on 3 Oct 2017
To programmatically implement selecting brush data, saving it to a newly created variable, you can try the following approach:
% Plot Random data
a = plot(rand(10,1));
% Enable Brush
brush on
% Now manually select brush data on the plot using the mouse
% then run the lines below
% Obtain indices of brushed values
ind = find(get(a, 'BrushData'));
% Obtain x and y brushed values
brush = logical(get(a, 'BrushData'));
xd = get(a, 'XData');
yd = get(a, 'YData');
brushed_x = xd(brush);
brushed_y = yd(brush);
There is an elaborate discussion of the above solution at:
A few other approaches that may be applicable to your use case are:
Of particular interest may be the "Graphical data selection tool" on File exchange.

Categories

Find more on Migrate GUIDE Apps 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!