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?
c = newline creates a newline character. newline is equivalent to char(10) or sprintf('\n') . Use newline to concatenate a newline character onto a character vector or a string, or to split text on newline characters.
newStr = split( str , delimiter ) divides each element of str at the delimiters specified by delimiter . The output newStr does not include the delimiters. newStr = split( str , delimiter , dim ) divides each element of str into a vector oriented along the dimension specified by dim .
newStr = splitlines( str ) splits str at newline characters and returns the result as the output array newStr . splitlines splits at actual newline characters, not at the literal \n . To split a string that contains \n , first use compose and then use splitlines .
To split a string by newline, call the split() method passing it the following regular expression as parameter - /\r?\ n/ . The split method will split the string on each occurrence of a newline character and return an array containing the substrings.
use sprinf and \n (newline character)
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: ']));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With