Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB line continuation within string

Tags:

string

matlab

In MATLAB, ... is used to continue a line to the next line. But if I want to continue a long string within quotation, what can I do? ... will be treated as a part of the string itself. Using [] is not a perfect solution since in most cases I use sprintf/fprintf to parse a long string like sql query. Using [] would be cumbersome. thanks.

like image 797
user 7023 Avatar asked Mar 07 '11 23:03

user 7023


People also ask

How do you continue a string on the next line in MATLAB?

If a statement does not fit on one line, enter three periods ( ... ) , also called dots, stops, or an ellipsis, at the end of the line to indicate it continues on the next line. Then press Enter or Return. Continue typing the statement on the next line.

How do you skip a line in a string in MATLAB?

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.

How do you split a string into multiple lines in MATLAB?

Description. 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 .

How do you split a line in MATLAB?

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 .


2 Answers

If you put the string in brackets, you can build it in several pieces:

s = ['abc' 'def' ... 
     'ghi'];

You can then split that statement into several lines between the strings.

like image 51
Jeremiah Willcock Avatar answered Oct 01 '22 13:10

Jeremiah Willcock


answer=['You can divide strings '...
    ,'by adding a comma '... 
    ,'(as you probably know one year later).'];
like image 26
Dan Avatar answered Oct 01 '22 15:10

Dan