Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Get t co-ordinate based off y co-ordinate

1 Ansicht (letzte 30 Tage)
Jamie Ford
Jamie Ford am 15 Okt. 2019
Geschlossen: MATLAB Answer Bot am 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

Antworten (1)

Star Strider
Star Strider am 15 Okt. 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!

Translated by