Referencing Static Functions in Matlab -


for object in matlab, possible call static function of same type without knowing encompassing package? right now, way i've found reference use package.whatever.staticfunction(), i'd encapsulate class having operate independent of whatever package it's in.

the solution i've found right is:

classdef whatever     methods(static)         function fig = staticfunction()              ...snip...         end     end     methods         function obj = whatever()             % call package.whatever.staticfunction();             eval(sprintf('%s.staticfunction();', class(obj)));         end     end end 

but seems clunky, slow, , incorrect. there better way it?

you can use instance call static method. looks non-static method call, it's not:

classdef statictest      methods (static)                 function dostatic()             fprintf('static!\n');         end     end      methods         function obj = statictest()             obj.dostatic()         end          function obj = donotstatic(obj)             fprintf('not static!\n');             obj.dostatic();         end     end  end 

usage:

>> x = statictest(); static! >> x.donotstatic(); not static! static! 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -