I have the code for a decaying sinusoid and I want to figure out how to reverse it
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Star Strider
2022-8-31
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!