Select 100 points either side from mouse click cooradinates

Need help!!
I have a line graph. I would like to get 100 points either side of the plot from mouse click coordinate.
I was looking at bsxfun fucntion
bsxfun(@plus,xcoods(:,2),-100:100) Can be used ?
I am using 2016a matlab version

4 commentaires

It doesn't sound like that would help you.
Can you confirm the following is what you mean?
You have a line graph. The user clicks somewhere in the axes, the coordinate being recorded with a function like getpts. Now you want 100 points of your graph directly to left of the click coordinate and 100 points of your graph to the right of the click coordinate?
Kurni Eswar
Kurni Eswar le 13 Juin 2019
Modifié(e) : Kurni Eswar le 13 Juin 2019
Exactly, This is want I what
Adam
Adam le 13 Juin 2019
Modifié(e) : Adam le 13 Juin 2019
What is wrong with the simplest possible answer:
xCoord + ( -100:100 );
? You can just repmat the y coordinate 201 times.
It works
Thanks

Connectez-vous pour commenter.

Réponses (2)

x = linspace(0,1) ;
y = sqrt(x) ;
% Mid point
M = [mean(x) mean(y)] ;
% points left side
idx1 = x<M(1) ;
% % points right side
idx2 = x>M(1) ;
figure
hold on
plot(x,y,'r') ;
plot(x(idx1),y(idx1),'.b')
plot(x(idx2),y(idx2),'.g')
legend('data','left points','right points')
Use the x-coordinate returned by getpts to select the data.
x=linspace(0,10,1000);
%generate a smooth random curve
y=sin(x)+polyval([0.01 0.1 1 10].*rand(1,4),x);
figure(1),clf(1)%only use clf during debugging
plot(x,y,'b','DisplayName','Data')
[xp,yp]=getpts;
if numel(xp)<1
clc,error('no points selected')
else
xp=xp(1);
end
pos_left=find(x<xp,100,'last');%might not return 100 points
pos_right=find(x>xp,100,'first');%might not return 100 points
hold on
plot(x(pos_left),y(pos_left),'.r','DisplayName','Left of click')
plot(x(pos_right),y(pos_right),'.g','DisplayName','Left of click')
hold off
legend

Catégories

En savoir plus sur Data Exploration dans Centre d'aide et File Exchange

Tags

Aucun tag saisi pour le moment.

Réponse apportée :

Rik
le 13 Juin 2019

Community Treasure Hunt

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

Start Hunting!

Translated by