Live editor text formatting

7 visualizzazioni (ultimi 30 giorni)
David Cole
David Cole il 27 Ott 2024
Risposto: 埃博拉酱 il 28 Ott 2024
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

Risposte (2)

Hitesh
Hitesh il 27 Ott 2024
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.

埃博拉酱
埃博拉酱 il 28 Ott 2024
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:

Categorie

Scopri di più su Graphics Object Properties in Help Center e File Exchange

Prodotti


Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by