Info

此问题已关闭。 请重新打开它进行编辑或回答。

Get t co-ordinate based off y co-ordinate

1 次查看(过去 30 天)
Jamie Ford
Jamie Ford 2019-10-15
关闭: MATLAB Answer Bot 2021-8-20
I am trying to get the t co-ordinate of the following graph when y = 40
t = 0 * pi:0.119:4 * pi;
a = 57;
phase_angle = 0.26;
y = a*sin((67*pi*t) + phase_angle);
plot(t,y);
so i want the co-ordinate (t, 40)
how can I get t?
Thanks

回答(1 个)

Star Strider
Star Strider 2019-10-15
Try these:
t = 0 * pi:0.119:4 * pi;
a = 57;
phase_angle = 0.26;
y = a*sin((67*pi*t) + phase_angle);
y_ofst = y-40;
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
y40 = zci(y_ofst);
for k = 1:numel(y40)
idxrng = y40(k)+[-1,1]
B = [t(idxrng); ones(size(t(idxrng)))].' \ y_ofst(idxrng).' % Linear Regression
xxct(k) = -B(2)/B(1)
end
figure
plot(t,y, xxct,40+[0 0],'pg')
alternatively:
for k = 1:numel(y40)
idxrng = y40(k)+[-1,1]
xxct(k) = interp1(y(idxrng), t(idxrng), 40) % Interpolation
end
figure
plot(t,y, xxct,40+[0 0],'pg')
Choose the most appropriate option for your application. Both give the same result.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by