Search code examples
matlabtext-processingword-wrap

Word Wrap in matlab editor involving strings


Thanks for the help in advance. Usually using ... in matlab allows a person to wrap lines in the editor. However when I enter something like this

error('Really long error message ... that I would like to wrap');

the "that I would like to wrap") portion loses its identity as a string. Is it possible to wrap code like this in matlab, and if so how would I do it?

Edit: The naive solution would be to break up the string into several strings, concatenate them, and save the result as a variable. I would like a cleaner solution though.


Solution

  • Well, if in the end the string is supposed to be one line, you can break out the string without having to divide the string by a given number. You don't have to do any calculation at all, each of your line does not need to be equal in length (or number of character) to the next line.

    Here is an example which runs without error (mmmh ... other than the one intended obviously!) :

    error([  
       'Really long error message ' ... 
       'that I would like to wrap ' ...
       'but each line in the editor doesn''t need to be the same lenght ' ...
       'because in the end it will be concatenated ' ...
       'in a single ' ...
       'line. The only thing that matters is to put a '' character at the beginning, and ' ...
       ' a ''... sequence of character at the end of each line' 
       ] );
    

    Granted it is not very elegant, but the only additional requirement to the ... is to add the ' symbol at the beginning end end of each line. The lines do not need to be consistent, you can break them when you like.