How would one print on the command window a 3x1 vector labeled "R" such that the output line matches the format as shown below? Currently I am using a bunch of fprintf functions and manually spacing out the outputs to make it look right, but I want to know if there's a more compact method of outputting and formatting text into command line.

 채택된 답변

Stephen23
Stephen23 2025년 3월 17일
편집: Stephen23 2025년 3월 17일

1 개 추천

R = [6640.441; 0; 0];
C = compose('%7s[%10.3f km]',["";"R = ";""],R);
fprintf('%s\n','A) Position with respect to the earth in PQW coordinates:',C{:})
A) Position with respect to the earth in PQW coordinates: [ 6640.441 km] R = [ 0.000 km] [ 0.000 km]

댓글 수: 1

Zayd
Zayd 2025년 3월 19일
Thank you! This works the most compactly.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Voss
Voss 2025년 3월 17일
편집: Voss 2025년 3월 17일

1 개 추천

R = [6640.441; 0; 0];
C = compose(' [ %8.3f km]',R);
C{2}([1 3]) = 'R=';
fprintf('%s\n',C{:});
[ 6640.441 km] R = [ 0.000 km] [ 0.000 km]

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

릴리스

R2024b

질문:

2025년 3월 17일

댓글:

2025년 3월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by