string MATLAB 字符串中的换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12619968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Line breaks in MATLAB strings
提问by Kristian
I am writing a code in which I am asking the user for an input. However the string informing the user about this is somewhat long, and when I use the code, it all gets written on a single line in the command window. I would like to have this spread over multiple lines. My code is:
我正在编写一个代码,我在其中要求用户输入。然而,通知用户这一点的字符串有点长,当我使用代码时,所有这些都写在命令窗口的一行中。我想让它分布在多条线上。我的代码是:
n = input(['The matrix is diagonally dominant. Please choose which method you wish to'...
' use: 1 (Gaussian elimination), 2 (Jacobi iterations),'...
' 3 (Gauss-Seidel iterations). If you enter any other number'...
' Gaussian elimination will automatically be used: ']);
If preferable, I would like to have this displayed over 4 lines, as in the code. How can I go about getting this done?
如果愿意,我希望将其显示在 4 行以上,如代码中所示。我怎样才能完成这件事?
回答by angainor
use sprinf and \n (newline character)
使用 sprinf 和 \n(换行符)
n = input(sprintf(['The matrix is diagonally dominant. Please choose which method you wish to\n'...
' use: 1 (Gaussian elimination), 2 (Jacobi iterations),\n'...
' 3 (Gauss-Seidel iterations). If you enter any other number\n'...
' Gaussian elimination will automatically be used: ']));
回答by Nick
Use \n
as an break character, for example:
使用\n
作为间隔字符,例如:
n = input(sprintf('blablabla\nblablabla\n'))