Live editor text formatting

조회 수: 6 (최근 30일)
David Cole
David Cole 2024년 10월 27일
답변: 埃博拉酱 2024년 10월 28일
I am using live editor and the fprintf command. I do not want a space between my outputs. I have not included \n but the output looks like double spacing. How can I get the second line to print directly below the first line without an addition line space?
Code
Output

답변 (2개)

Hitesh
Hitesh 2024년 10월 27일
Hi David Cole,
The "fprintf" function does not inherently add spaces or newlines to your output unless specified. However, if it appears that there is an extra line space, it could be due to how the Live Editor formats the output.
You can get your output directly below the previous output without any additional line spaces by using following method:
  • Concatenate Strings: You can print multiple pieces of text, concatenate them into a single string before using "fprintf".
fprintf(['Transmission Line losses Bus 1-2: 11.4214 MW and 45.6857 MVAR\n', ...
'Transmission Line losses Bus 1-3: 1.8218 MW and 7.2872 MVAR']);
  • Use "disp" with "sprintf": You need to use "disp" with "sprintf" as it controls formatting better in the Live Editor.
disp(sprintf('Transmission Line losses Bus 1-2: 11.4214 MW and 45.6857 MVAR'));
disp(sprintf('Transmission Line losses Bus 1-3: 1.8218 MW and 7.2872 MVAR'));
  • Verify Live Editor Settings: Kindly ensure there are no specific settings in the Live Editor affecting the output format.

埃博拉酱
埃博拉酱 2024년 10월 28일
When using fprintf in a live script, each line of output is independent. The output of your two calls will be placed in two text boxes, with no blank lines in between, just a certain distance to make it look as if there are blank lines.
If you need them to be in the same text box, you may:
  • Concatenate the strings with line breaks, as shown by @Hitesh
  • NOT use disp with sprintf. This makes no difference as I've tested.
  • Compress your fprintfs into one same line or for loop:

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by