| MATLAB® | ![]() |
| On this page… |
|---|
Classes are defined in M-files just like scripts and functions. To use the editor or debugger with a class file, you must use the full class name. For example, suppose the M-file for a class, myclass.m is in the following location:
+PackDir1/+PackDir2/@myclass/myclass.m
To open myclass.m in the MATLAB® editor, you could reference the file using dot-separated package names:
edit PackDir1.PackDir2.myclass
You could also use path notation:
edit +PackDir1/+PackDir2/@myclass/myclass
If myclass.m is not in an @-directory, then you can type:
edit +PackDir1/+PackDir2/myclass
To refer to functions inside a package directory you can use dot or path separators:
edit PackDir1.PackDir2.packFunction edit +PackDir1/+PackDir2/packFunction
To refer to a function defined in its own M-file inside of a class @-directory, you can use the following:
edit +PackDir1/+PackDir2/@myclass/myMethod
For debugging, dbstop accepts any of the file specifications used by the edit command.
If you modify a class definition (i.e., change attributes or the specification of classdef, properties, methods, or events blocks), then these changes might not take affect immediately unless there are no instances of the class. MATLAB does not use a modified class definition while any instance of a previous definition exists in MATLAB. Instead, MATLAB continues to use the old definition until all instances are cleared.
You can use the clear command:
clear classes
to clear the current workspace of all variables, clear all functions (which might have persistent variables holding class instances), and clear all classes that are not instantiated. Note that clearing classes clears all variables in the workspace.
However, you are not required to issue the clear classes command after changing the code in a method's function definition. MATLAB executes the changed method the next time the method is called.
![]() | Using Objects to Write Data to a File | Compatibility with Previous Versions | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |