Main Content

Use of Editor and Debugger with Classes

Write Class Code in the Editor

The MATLAB® code editor provides an effective environment for class development. The Code Analyzer, which is built into the editor, check code for problems and provides information on fixing these problems. For information on editor use and features, see edit.

How to Refer to Class Files

Define classes in files just like scripts and functions. To use the editor or debugger with a class file, use the full class name. For example, suppose the file for a class, myclass.m is in the following location:


To open myclass.m in the MATLAB editor, you could reference the file using dot-separated namespace names:

edit nspfld1.nspfld2.myclass

You could also use path notation:

edit +nspfld1/+nspfld2/@myclass/myclass

If myclass.m is not in a class folder, then enter:

edit +nspfld1/+nspfld2/myclass

To refer to functions inside a namespace folder, use dot or path separators:

edit nspfld1.nspfld2.nspFunction
edit +nspfld1/+nspfld2/nspFunction

To refer to a method defined in its own file inside a class folder, use:

edit +nspfld1/+nspfld2/@myclass/myMethod

How to Debug Class Files

For debugging, dbstop enables you to set breakpoints in the class constructor by specifying the fully qualified class file name. To set a breakpoint at a method defined in the class file, specify the line number of the method with the dbstop command. For example, if the method begins on line 14 in the classdef file, myclass.m, use this command to put a breakpoint on the first executable line of the method.

dbstop in myclass at 14

See Automatic Updates for Modified Classes for information about clearing class after modification.

See Also

Related Topics