Effacer les filtres
Effacer les filtres

How to find x values of specified y point on the graph ?

107 vues (au cours des 30 derniers jours)
Zack Trahem
Zack Trahem le 19 Juil 2022
Let say i have two array x[1,2,3,4,5] and y[6, 7,8,9,10 ] i want to find the x values of the 6.34 on the graph. I want to put marker for that point is there any way to do it?

Réponses (3)

Voss
Voss le 19 Juil 2022
x = [1,2,3,4,5];
y = [6,7,8,9,10];
y_point = 6.34;
x_point = interp1(y,x,y_point);
plot(x,y);
hold on
plot(x_point,y_point,'r.')
  1 commentaire
Zack Trahem
Zack Trahem le 19 Juil 2022
Thank you for quick response. this look like what i looking for. However, my y vector is not sorted in assending order and unique. I attached figure.

Connectez-vous pour commenter.


Sam Chak
Sam Chak le 19 Juil 2022
Hi Zack,
You can use interp1 technique.

Star Strider
Star Strider le 19 Juil 2022
Using the supplied .fig file —
F = openfig('graph1.fig');
Lines = findobj(gca, 'Type','line');
x = Lines.XData;
y = Lines.YData;
yval = 0.0100277; % Choose A Value Within tThe Range Of 'y'
yxi = find(diff(sign(y-yval)));
for k = 1:numel(yxi)
idxrng = max(1,yxi(k)-1) : min(numel(y),yxi(k)+1);
xv(k) = interp1(y(idxrng), x(idxrng),yval);
yv(k) = yval;
end
% figure
% plot(x, y)
hold on
plot(xv, yv, 'rs', 'MarkerSize',10)
hold off
.

Catégories

En savoir plus sur Graphics Object Identification dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by