필터 지우기
필터 지우기

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 (최근 30일)
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.

답변 (2개)

Torsten
Torsten 2022년 12월 13일
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 2022년 12월 13일
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
gowtham balu
gowtham balu 2022년 12월 14일
I humbly Thank you for your speedy and timely response and answers........
With regards,
Gowtham

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by