Displaying Output in Command Window

3 Ansichten (letzte 30 Tage)
Eli Wolkenstein
Eli Wolkenstein am 23 Apr. 2023
Beantwortet: Walter Roberson am 23 Apr. 2023
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)

Antworten (1)

Walter Roberson
Walter Roberson am 23 Apr. 2023
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

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by