How can I automatically select two points in a plot?

4 ビュー (過去 30 日間)
Sin j
Sin j 2020 年 1 月 13 日
回答済み: Cameron B 2020 年 1 月 13 日
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 Center および File ExchangeData Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by