Displaying Output in Command Window

조회 수: 4 (최근 30일)
Eli Wolkenstein
Eli Wolkenstein 2023년 4월 23일
답변: Walter Roberson 2023년 4월 23일
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에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by