I have the code for a decaying sinusoid and I want to figure out how to reverse it

1 vue (au cours des 30 derniers jours)
Gonzalo
Gonzalo le 31 Août 2022
function xs = myDecayingSinusoid(A, b, omega, phi, fs, tStart, tEnd)
A = 6;
b = .9;
omega = 60 .* 2 .* pi;
phi = pi ./ 3;
fs = 15;
tStart = 0;
tEnd = 3;
tt = [tStart:1 / fs: tEnd];
xs = A * exp(-b * tt) .* cos(omega * tt + phi);
plot(tt, xs, 'b-')
end

Réponses (1)

Star Strider
Star Strider le 31 Août 2022
I have no idea what ‘reverse’ means in this context. If you want to change ‘tt’ the easiest way is to re-code it as:
tt = linspace(tStart, tEnd, 1/Fs)/Fs;
then to revferse it simply reverse the values of ‘tStart’ and ‘tEnd’ in the function call. The linspace function does the rest. If you want to reverse the direction of the x-axis, after the plot call, add:
set(gca, 'XDir','reverse')
And of course, you can do both. Note that changing the linspace arguments alone will not change the plot appearance, because plot always plots with increasing values of the independent (x) variable vector.

Catégories

En savoir plus sur Graphics Objects dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by