【问题标题】:Comment out some part of a line in matlab function在matlab函数中注释掉一行的一部分
【发布时间】:2014-08-04 00:50:32
【问题描述】:

正如问题所暗示的,我想在 MATLAB 中注释掉一行的某些部分。

我还想注释掉一行的某些部分,直到行尾。

原因是,我必须尝试一条线的两个不同版本,并且我不想复制这条线两次。我知道如果我复制该行很容易评论/取消评论,但我想要这样。

【问题讨论】:

  • 我也只是在寻找这个功能,准备使用~ 字符来替换一些未使用的变量,但想用多行注释保留它们的名称,就像你会看到的说function( ~ /* param1 */ , ~ /* param2 */ ) 如果我正在使用 C++、Java 或 C#。

标签: matlab comments


【解决方案1】:

不可能在一行内(afaik),但您可以将您的术语分成多行:

x=1+2+3 ... optional comments for each line
... * factorA ... can be inserted here
* factorB ...
+4;

这里 * factorA 被注释掉,* factorB 被使用,导致术语x=1+2+3*factorB+4。

The documentation contains a similar example, commenting out one part of an array:

header = ['Last Name, ',      ...
          'First Name, ',     ...
      ... 'Middle Initial, ', ...
          'Title']

【讨论】:

  • 这是对续行语法的惊人滥用。文档似乎说没关系!
  • Daniel.... 这很酷,哈哈。我知道... 注释掉了该行的其余部分,但以这种方式使用它既可怕又令人敬畏。
【解决方案2】:

不,这是不可能的。来自help '%':

%   Percent.  The percent symbol is used to begin comments.
    Logically, it serves as an end-of-line character. Any
    following text on the line is ignored or printed by the
    HELP system.

所以只需复制粘贴该行,或编写一个小函数,以便更容易在版本之间切换。

【讨论】:

    猜你喜欢
    • 2021-10-11
    • 1970-01-01
    • 1970-01-01
    • 2018-11-18
    • 2015-12-23
    • 2015-07-09
    • 2018-02-19
    • 2018-06-02
    • 1970-01-01
    相关资源
    最近更新 更多