Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Get t co-ordinate based off y co-ordinate

1 visualizzazione (ultimi 30 giorni)
Jamie Ford
Jamie Ford il 15 Ott 2019
Chiuso: MATLAB Answer Bot il 20 Ago 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

Risposte (1)

Star Strider
Star Strider il 15 Ott 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.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by