Finding X value with known Y value on plot
显示 更早的评论
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 个评论
Rik
2017-11-4
You will have to interpolate this function. Unless you are so lucky that you have the exact intersecting coordinates in both plots, there is no other way.
Serena Solanki
2017-11-6
Kelb77
2017-11-6
Curve fit the data, plot a new curve once you have the function, interpolate from that
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
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 个评论
Walter Roberson
2020-9-10
At the moment the loop looks to me to be doing about the same as ppval() would do?
KSSV
2017-11-7
0 个投票
类别
在 帮助中心 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
