Display long statements on multiple lines in output

Hello All,
I want to include some texts in the description of a structure. But it#s too long to be displayed in a single line. I want that to be displayed in 2 or 3 lines.
Any suggestions on how to do it?
Thanks

 Respuesta aceptada

José-Luis
José-Luis el 6 de Sept. de 2012
One way to go. Insert newline in your string, and display using fprintf:
yourString = 'One line \n Two line \n Three line';
fprintf(your_String);

4 comentarios

Swasti Khuntia
Swasti Khuntia el 6 de Sept. de 2012
Editada: Swasti Khuntia el 6 de Sept. de 2012
Hello Jose, I want to include text in my structure. While storing the text, I want that they should be displayed in 2 lines rather than single line because it's too long. For e.g.,
data.description ='I want to display in two lines';
The structure should show output as
I want to
display in two lines
I hope you got it.
Thanks
José-Luis
José-Luis el 6 de Sept. de 2012
Editada: José-Luis el 6 de Sept. de 2012
This will display it as three lines in the command window.
data.description = ['One line ' char(10) 'Two Line' char(10) 'Three Line']
If you want it in three lines in the variable editor:
data.description{1} = 'One Line';
data.description{2} = 'Two Line';
data.description{3} = 'Three Line';
Thanks a lot !!! It' perfect !!!
Mohammed Musleh
Mohammed Musleh el 23 de Sept. de 2018
Editada: Mohammed Musleh el 24 de Sept. de 2018
Doing this in 2018, on version 2018a, Matlab is suggesting that I switch "char(10)" with just "newline" (outside of the single quotes). Works well.
But I prefer the compose function: https://www.mathworks.com/help/matlab/ref/compose.html

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Sept. de 2012

Editada:

el 24 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by