Format output with constant display values

2 ビュー (過去 30 日間)
Ethan Rando
Ethan Rando 2020 年 11 月 19 日
回答済み: Fangjun Jiang 2020 年 11 月 19 日
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 Center および File ExchangeFourier Analysis and Filtering についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by