Multiline string literal in Matlab?

robince picture robince · Jan 9, 2013 · Viewed 12k times · Source

Is there a multiline string literal syntax in Matlab or is it necessary to concatenate multiple lines?

I found the verbatim package, but it only works in an m-file or function and not interactively within editor cells.

EDIT: I am particularly after readbility and ease of modifying the literal in the code (imagine it contains indented blocks of different levels) - it is easy to make multiline strings, but I am looking for the most convenient sytax for doing that.

So far I have

t = {...
'abc'...
'def'};
t = cellfun(@(x) [x sprintf('\n')],t,'Unif',false);
t = horzcat(t{:});

which gives size(t) = 1 8, but is obviously a bit of a mess.

EDIT 2: Basically verbatim does what I want except it doesn't work in Editor cells, but maybe my best bet is to update it so it does. I think it should be possible to get current open file and cursor position from the java interface to the Editor. The problem would be if there were multiple verbatim calls in the same cell how would you distinguish between them.

Answer

edgar.holleis picture edgar.holleis · Jan 9, 2013

I'd go for:

multiline = sprintf([ ... 
'Line 1\n'... 
'Line 2\n'... 
]);