Private Methods

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Although MuPAD® does not let you declare a method as private, you can create private methods by using closures.

MuPAD uses a fundamentally simple object and name lookup model. Objects are data that belong to a particular domain type, and domains have named entries (called slots). If the value of a slot is a function, this entry is called a method. Therefore, MuPAD lets you use the same techniques for hiding method calls as you use for hiding utility functions. For details, see Utility Functions in Closures.

This example creates the private method f of the domain d. This method is not accessible from methods in inherited domains and from category methods:

domain d
  local f;
  inherits Dom::BaseDomain;
  g := proc()
       begin
         print("g");
         f();
       end;
begin
  f := proc()
       begin
         print("f");
       end;
end:
d::f

d::g()