Format output with constant display values

2 次查看(过去 30 天)
Hello, how would I format this code so that it has an output display of
(2*pi*X2)/period
Where the displayed output is not simplified and the denominator is always period (60) and the numerator is always displayed as 2*pi*_.
Basically I want the format to be the same but only the X2 value to change, no simplification.
fs = 5400;
T = 1/fs;
n = 0:959; %sample 960
t = n * T;
xn = cos(540*pi*t) + cos(3600*pi*t) + cos(5040*pi*t);
A = sym([(540*pi)/5400, (3600*pi)/5400, (5040*pi)/5400]);
X = gcd(A);
X2 = A ./ X
[n, d] = numden(X);
n = n * 2;
d = d * 2;
num = X2 * n;
den = [d d d];
period = d; %60
pretty((2*pi*X2)/period);

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2020-11-19
%%
X2=5.6;
period=60;
fprintf('2*pi*%g/%g\n',X2,period);

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by