Info

This question is closed. Reopen it to edit or answer.

Get t co-ordinate based off y co-ordinate

1 view (last 30 days)
Jamie Ford
Jamie Ford on 15 Oct 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
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

Answers (1)

Star Strider
Star Strider on 15 Oct 2019
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.

Tags

Community Treasure Hunt

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

Start Hunting!