Display without new line
이전 댓글 표시
To demonstrate various formats of MATLAB, I use the following script:
x = 1/7;
format short, fprintf(['format short: ']), x % default
format short e, fprintf(['format short e: ']), x
format short g, fprintf(['format short g: ']), x
format long, fprintf(['format long: ']), x
format long e, fprintf(['format long e: ']), x
format long g, fprintf(['format long g: ']), x
format rat, fprintf(['format rat: ']), x % ne pas utiliser avec des nombres irrationnels
format bank, fprintf(['format bank: ']), x % format 'bancaire'
When I run it I get the following output:

How can I display the format description and the corresponding value in the same line?
I apologize if the question is a trivial one.
Thank you very much in advance.
채택된 답변
추가 답변 (1개)
Fangjun Jiang
2023년 7월 11일
편집: Fangjun Jiang
2023년 7월 11일
use sprintf() and check "doc sprintf" to learn the % Formatting Operator
sprintf('format short: %f',x)
sprintf('format short: %e',x)
If solely for the demonstration of MATLAB Command Window formatting, use
format short, fprintf(['format short: ']);disp(x)
카테고리
도움말 센터 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!