Get Coordinate of multiple plots with same x axis

Hi,
I have 2 plots on same graph, suppose p1 and p2 ( just to explain my qn I am taking 2 random )
Now I click on the p1 plot point which will give me co-ordinates (x,y1), where y1 is the value at x from p1 plot
but when I do so, I also want to see (x,y2) that is, when I click on p1 plot, accordingly I want to see value from both the plots.
Is it possible to do so?
Please Help.
I hope my qn is clear.
sample=0.006;
t=10;
time=[1:sample:t];
p1=rand(1,length(time));
p2=rand(1,length(time));
subplot(2,1,1)
plot(time,p1)
subplot(2,1,2)
plot(time,p2)

3 comentarios

Try ginput
x = linspace(1,10,10);
y1 = 2.*x;
y2 = sin(x);
[x0,y0] = ginput(1); % ask user to make a click
X = [x(:) x(:)]; % get the data together
Y = [y1(:) y2(:)]; % get the data together
D = hypot(x0-X,y0-Y); % distances
[m,ix] = min(D); % find closest points
s1 = sprintf('x_1: %f; y_1: %f',X(ix(1),1),Y(ix(1),1));
s2 = sprintf('x_2: %f; y_2: %f',X(ix(2),2),Y(ix(2),2));
text(x0,y0,[s1 newline s2])
Thank you sir
darova
darova el 4 de Ag. de 2021

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Preguntada:

el 2 de Ag. de 2021

Comentada:

el 4 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by