Azzera filtri
Azzera filtri

Finding x-intercept in a 2d plot shown below, there are multiple loops I want to find all the values of X at Y=0...Please help..

6 visualizzazioni (ultimi 30 giorni)
I have a 2D plot and I want to find x-intercept(x at y=0) for all the loops shown in the figure attached. Anyone please post relevant command and how can i use it in matlab.
If there is 2D raw data required I can share that too.
Thanks everyone.

Risposte (2)

Torsten
Torsten il 13 Dic 2022
If you have the x-y values as vectors available, you can use this code to determine the x-values where y=0:
i = find(y(1:end-1).*y(2:end) <= 0)
x_root = x(i)-y(i).*(x(i+1)-x(i))./(y(i+1)-y(i))

Star Strider
Star Strider il 13 Dic 2022
Something like this should work —
%Finding X value with known Y value on plot
t = linspace(0, 2*pi, 1000); % Create Data
ph = -rand(10,1);
x = cos(2*pi*t*5 + zeros(size(ph)));
y = sin(2*pi*t*5 + ph);
x = reshape(x.',[],1);
y = reshape(y.',[],1);
figure
plot(x, y)
grid
axis('padded')
zxi = find(diff(sign(y))); % Indices Of Approximate Y-Zero-Crossings
for k = 1:size(zxi)
idxrng = max(1,zxi(k)-1) : min(numel(x),zxi(k)+1);
xv(k,:) = interp1(y(idxrng), x(idxrng), 0);
% yv(k,:) = interp1(x, ABC(k,:), xv(k,:));
end
xv
xv = 639×1
0.7099 -0.7088 0.7080 -0.7074 0.7071 -0.7072 0.7074 -0.7080 0.7088 -0.7100
% yv
figure
plot(x, y, 'DisplayName', 'Original Data')
hold on
plot(xv, zeros(size(xv)), '+r', 'DisplayName', 'X-Intersections')
hold off
grid
legend('Location','eastoutside')
axis('padded')
This uses synthetic data. It detects all the y-vector zero-crossings and returns the corresponding x-values in ‘xv’, and plots them.
It should work with your data without alteration, although it will require that you assign the appropriate values to ‘x’ and ‘y’ in my code.
.
  5 Commenti

Accedi per commentare.

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Prodotti


Release

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by