Matlab将注释调整为每行一定的长度

我喜欢MATLAB在每行的某个限制上自动换行注释.现在让我们假设我添加了以下注释:

% a) this is a test comment. this is a test comment. this is a test comment
%    this is a test comment. this is a test comment. this is a test
%    comment! this is a test comment!

在开头用手动缩进(以适应a)).现在,当我需要更改一些评论时,例如在第一行插入一些单词,第一行变得太长.如何自动将其新格式化为正确的最大值.线长但仍然手动缩进?
有没有自动的方法来做到这一点?

最佳答案 我认为你能做的最好的事情需要你做三个步骤.

当您最初添加一些文本时,它看起来像这样:

% a) this is a test comment. this is a test comment. ADDED TEXT this is a test comment
%    this is a test comment. this is a test comment. this is a test
%    comment! this is a test comment!

首先,选择文本(或通过CTRL a选择整个文件),然后使用CTRL J发出“wrap comments”命令.现在你的文字看起来像这样:

% a) this is a test comment. this is a test comment. ADDED TEXT this is a
% test comment
%    this is a test comment. this is a test comment. this is a test
%    comment! this is a test comment!

其次,您必须手动缩进第一行,因此文本如下所示:

% a) this is a test comment. this is a test comment. ADDED TEXT this is a
%    test comment
%    this is a test comment. this is a test comment. this is a test
%    comment! this is a test comment!

第三,选择文本并再次使用CTRL J.您的文字将如下所示:

% a) this is a test comment. this is a test comment. ADDED TEXT this is a
%    test comment this is a test comment. this is a test comment. this is a
%    test comment! this is a test comment!

它并不完美,但它在Matlab编辑器中就像我所知道的一样好.

点赞