Printing an embedded newline character in a string using fprintf

13 vues (au cours des 30 derniers jours)
Frankie Camacho
Frankie Camacho le 21 Sep 2021
Modifié(e) : Jan le 21 Sep 2021
I have a string that I would like to print using fprintf, but I want to embed a newline character in the string as part of the argument. Here is the output to the below code:
mystring =
"This is my string.\nIt is too long so I use newline\ncharacters to print on the next line."
This is my string.\nIt is too long so I use newline\ncharacters to print on the next line.
mystring = "This is my string.\nIt is too long so I use newline\ncharacters to print on the next line.";
fprintf('%s',mystring);

Réponses (1)

Jan
Jan le 21 Sep 2021
Modifié(e) : Jan le 21 Sep 2021
mystring = "This is my string.\nIt is too long so I use newline\ncharacters to print on the next line.";
fprintf(mystring);
This is my string. It is too long so I use newline characters to print on the next line.
Or:
mystring = "This is my string.\nIt is too long so I use newline\ncharacters to print on the next line.";
str = sprintf(mystring);
fprintf('%s', str)
This is my string. It is too long so I use newline characters to print on the next line.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by