Live editor text formatting

37 visualizaciones (últimos 30 días)
David Cole
David Cole el 27 de Oct. de 2024 a las 15:43
Respondida: 埃博拉酱 el 28 de Oct. de 2024 a las 14:03
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

Respuestas (2)

Hitesh
Hitesh el 27 de Oct. de 2024 a las 16:37
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.

埃博拉酱
埃博拉酱 el 28 de Oct. de 2024 a las 14:03
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:

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by