How can I automatically select two points in a plot?
4 views (last 30 days)
Show older comments
Hello,
How can I automatically select two points in a plot?
I use ginput manually, but I want to automate the selection.
You can see part of the code below:
x = (1:length(compositfilt));
y = compositfilt;
hold on
grid on
xlabel('time [s]');
ylabel('voltage');
plot(x,y)
[cut1, ~] = ginput(2);
cut1 = round(cut1);
compositfilt = compositfilt(:,cut1(1):cut1(2));
clf
x = (1:length(compositfilt));
y = compositfilt;
plot(x , y)
0 Comments
Answers (1)
Cameron B
on 13 Jan 2020
Select them as in producing data tips? If that's the case, then see the code below. If not, then please explain what you'd like a little bit more.
xx = 1:1:30;
yy = sqrt(xx);
fig = figure;
figplot = plot(xx,yy);
CursorPt1 = createDatatip(datacursormode(fig),figplot);
CursorPt2 = createDatatip(datacursormode(fig),figplot);
CursorPt1.Marker = 'o';
CursorPt2.Marker = 'o';
CursorPt1.MarkerSize = 5;
CursorPt2.MarkerSize = 5;
CursorPt1.Position = [xx(3),yy(3)];
CursorPt2.Position = [xx(6),yy(6)];
0 Comments
See Also
Categories
Find more on Data Exploration 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!