How to know interpolated points in a MATLAB plot?

12 vues (au cours des 30 derniers jours)
Alessandro Picca
Alessandro Picca le 20 Mar 2023
Modifié(e) : Bruno Luong le 21 Mar 2023
Hi everyone,
I have the plot of data received from a VNA. To read the bandwidth I need to know the coordinates of the points that have the y coordinate -10. This data is not present in the VNA data sheet, but MATLAB interpolates it with the plot function. How can I find the points with coordinate y = -10 from the code?
Thanks a lot everyone!

Réponse acceptée

Bruno Luong
Bruno Luong le 20 Mar 2023
Modifié(e) : Bruno Luong le 21 Mar 2023
% Dummy example of some curve that cross the horizontal line y=10
x = cumsum([0 rand(1,40)]);
y = 12*sin(x);
plot(x,y,'.-');
hl = findobj(gca, '-depth', 1, 'type', 'line');
x=get(hl,'xdata');
y=get(hl,'ydata');
y10 = -10;
i = find((y(1:end-1)-y10).*(y(2:end)-y10) < 0);
ipick = i(1); % select where it cross and where x is (in your graph it has at lzast 2 crossing points)
x10 = interp1(y(ipick:ipick+1),x(ipick:ipick+1),y10)
x10 = 4.1678
hold on
xline(x10)
yline(y10)
plot(x10,y10,'ro','Markersize',10)

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by