【问题标题】:possible to overload function in matlab class?可以在 matlab 类中重载函数吗?
【发布时间】:2011-12-26 14:14:58
【问题描述】:

是否可以在您创建的 Matlab 类中重载函数?

如下:

    function [ sigma_nc ] = sustained_interference( N )
       sustained_interference( N, N.center_freq);
    end

    function [ sigma_nc ] = sustained_interference( N, center_freq )
       ...
    end

不幸的是,当我尝试这个时,我得到一个重新定义错误

【问题讨论】:

标签: function matlab overloading


【解决方案1】:

如果您使用后者创建函数,那么您可以只传递一个参数,该参数将被解释为第一个。如果你想要默认值,那么你可以这样做:

function [ sigma_nc ] = sustained_interference( N, center_freq )
   if nargin < 2
       center_freq = N.center_freq;
   end
   ...
end

【讨论】:

  • a-ha,我们开始...我需要 nargin 来完成这项工作。非常感谢!当它允许我接受你的回答时,我会的。
猜你喜欢
  • 2019-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多