How can I automatically select two points in a plot?

6 次查看(过去 30 天)
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)

回答(1 个)

Cameron B
Cameron B 2020-1-13
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)];

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by