包含字符串的matlab编辑器中的Word Wrap

时间:2014-05-06 17:50:51

标签: matlab text-processing word-wrap

提前感谢您的帮助。通常在matlab中使用...允许一个人在编辑器中换行。但是当我输入这样的东西时

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

“我想要包装”)部分失去其作为字符串的身份。是否有可能在matlab中包装这样的代码,如果是这样,我该怎么办呢?

编辑: 天真的解决方案是将字符串分解为多个字符串,将它们连接起来,并将结果保存为变量。我想要一个更清洁的解决方案。

2 个答案:

答案 0 :(得分:3)

好吧,如果最后字符串应该是一行,你可以打破字符串,而不必将字符串除以给定的数字。你根本不需要进行任何计算,你的每一行的长度(或字符数)都不需要与下一行相等。

这是一个没有错误运行的例子(mmmh ......显然不是那个!):

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' 
   ] );

虽然它不是很优雅,但...的唯一额外要求是在每行的开头端添加'符号。线条不需要一致,你可以在你喜欢的时候打破它们。

答案 1 :(得分:2)

Appproach 1:我认为如果它适合您的清洁方式,您可以尝试使用单元格阵列方法,不过我认为它在概念上类似于@Hoki的方法 - < / p>

emsg = [{'Really long error message that we are trying really really '} ...
    {'hard to fit into one line, because if we do not, then we are '} ...
    {'doomed.'}]

error(horzcat(emsg{:}))

Appproach 2:可以考虑使用strcat的另一种方法,这可能是一个更小的清洁和直接(至少与单元阵列方法相比) -

msg = strcat( ...
    'Really long error message that we are trying really really ', ...
    'hard to fit into one line, because if we do not, then we are ', ...
    'doomed.');

error(msg)
相关问题