Displaying Output in Command Window

3 次查看(过去 30 天)
How can I display the outputs for the variables dr through ts in the command window neatly? (every line will say the name of the variable and show its value)
a1=input('A1: ');
t1=input('t1: ');
a2=input('A2: ');
t2=input('t2: ');
dr=log(a1/a2)/sqrt((4*pi^2)+(log(a1/a2)^2));
T=t2-t1;
wn=(2*pi)/(T*sqrt(1-dr^2));
wd=wn*sqrt(1-dr^2);
Mp=exp((pi*dr)/sqrt(1-dr^2));
tp=pi/wd;
tr100=(pi-atan(-dr*sqrt(1-dr^2))/wn*sqrt(1-dr^2));
tr90=(0.8+2.5*dr)/wn;
ts=4/(dr*wn);
X=[' Damping Ratio: ',dr,' Period: ',T,' Undamped Frequency: ',wn,' Damped Frequency: ',wd,' Maximum Overshoot: ',Mp,' 0-100% Rise Time: ',tr100,' 10-90% Rise Time: ',tr90,' Settling Time: ',ts];
disp(X)

回答(1 个)

Walter Roberson
Walter Roberson 2023-4-23
One way would be
X = " Damping Ratio: " + dr + " Period: " + T + " Undamped Frequency: " + wn + " Damped Frequency: " + wd + " Maximum Overshoot: " + Mp + " 0-100% Rise Time: " + tr100 + " 10-90% Rise Time: " + tr90 + " Settling Time: " + ts;
For values that are not integers, the number of significant digits that this will use after the decimal place is a bit variable (generally 4)
If you want more control over the format or number of decimal places, see compose or sprintf or fprintf

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by