简体   繁体   中英

possible to overload function in matlab class?

Is it possible to overload a function in a Matlab class that you've created?

Like the following:

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

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

Unfortunately when I try this, I get a redefinition error

If you create the function using the latter, then you can pass it just a single parameter which will be interpreted as the first. If you want default values, then you can do something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM