8

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

gnychis
  • 7,289
  • 18
  • 75
  • 113

1 Answers1

9

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
PengOne
  • 48,188
  • 17
  • 130
  • 149
  • a-ha, there we go... I needed the nargin to make this work. Thanks a bunch! When it allows me to accept your answer, I will. – gnychis Nov 10 '11 at 22:26