Finding X value with known Y value on plot

조회 수: 16 (최근 30일)
Serena Solanki
Serena Solanki 2017년 11월 4일
답변: SAiF AlNaQBi 2020년 9월 26일
I have plotted a graph based on known sets of data for x and y. I have then added a horizontal line to the plot at the y-value where I want to find out the corresponding x-values (shown in red on the plot).
I want to know what the x-values are where these two lines intercept. I do not have the equation for the blue signal. Is there a function/ command I could use that will do this?
% step one of inputting file
filename='Test_Results_19.xls'
ColumnA= xlsread(filename,'A2:A2088')
ColumnB= xlsread(filename,'B2:B2088')
B=ColumnB
A=ColumnA
%Step 2- do the FFT of the values
Z=fft(A)
W=fft(B)
%Step 3 find the modulus of values in column B
X=abs(Z)
Y=abs(W)
plot(X,Y)
title('Magnitude of frequency against frequency')
xlabel('Frequency')
ylabel('H(w)')
%finding the peak value and W1 and W2
[fmax, imax]=max(Y);
Qmax=fmax;
Q2=(Qmax/sqrt(2));
%Need to find corresponding x-values to the found y-values
x1=0
x2=45*10^4
y1=Q2
plot(X,Y,[x1 x2],[y1 y1])
hold on;
  댓글 수: 4
Kelb77
Kelb77 2017년 11월 6일
Curve fit the data, plot a new curve once you have the function, interpolate from that
Walter Roberson
Walter Roberson 2017년 11월 6일
You might want to look in the File Exchange for keyword "digitize", as there are some tools to convert plot images into data values.

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

답변 (3개)

Akira Agata
Akira Agata 2017년 11월 7일
One possible way to find the threshold-crossing points is interpolating the data by spline function and find the crossing points by using fzero function. The following is the sample script to do this.
% Sample data y = f(x)
x = linspace(-2*pi, 2*pi, 15);
y = sech(x) + 0.2*rand(size(x));
% Threshold
th = 0.5;
% Spline interpolation
pp = spline(x,y);
% Find the indexes where y(i) < th and y(i+1) > th
idx = find((y(1:end-1)-th).*(y(2:end)-th) < 0);
% Find the root of f(x)-th = 0
x0 = zeros(size(idx));
y0 = zeros(size(idx));
pt = 1;
for kk = idx
x1 = x(kk);
func = @(x) pp.coefs(kk,:)*[(x-x1)^3; (x-x1)^2; (x-x1);1]-th;
[x0(pt),y0(pt)] = fzero(func,x(kk));
pt = pt+1;
end
% Show the result
xx = -2*pi:0.1:2*pi;
yy = spline(x,y,xx);
figure
plot(x,y,'-o')
hold on
plot(xx,yy)
plot([-2*pi 2*pi],[th th])
plot(x0,y0+th,'ro')
legend({'Data','Spline interpolation','Threshold','Estimated points'})
  댓글 수: 2
Imran
Imran 2020년 9월 10일
편집: Imran 2020년 9월 10일
Can you please explain the for loop portion of the code?
Walter Roberson
Walter Roberson 2020년 9월 10일
At the moment the loop looks to me to be doing about the same as ppval() would do?

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


KSSV
KSSV 2017년 11월 7일

SAiF AlNaQBi
SAiF AlNaQBi 2020년 9월 26일

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by