Programming and Data Types |
Creating M-Files: Accessing Text Editors
M-files are ordinary text files that you create using a text editor. MATLAB provides a built-in editor, although you can use any text editor you like.
Another way to edit an M-file is from the MATLAB command line using the edit
function. For example,
edit
foo
opens the editor on the file foo.m
. Omitting a filename opens the editor on an untitled file.
You can create the fact
function shown on the previous page by opening your text editor, entering the lines shown, and saving the text in a file called fact.m
in your current directory.
Once you've created this file, here are some things you can do:
fact.m
fact
function
Note
Save any M-files you create and any MathWorks-supplied M-files that you edit in a directory that is not in the $matlabroot/toolbox directory tree. If you keep your files in $matlabroot/toolbox directories, they may be overwritten when you install a new version of MATLAB. Also note that locations of files in the $matlabroot/toolbox directory tree are loaded and cached in memory at the beginning of each MATLAB session to improve performance. If you save files to $matlabroot/toolbox directories using an external editor, or if you add or remove files from these directories using file system operations, enter the commands clear functionname and rehash toolbox before you use the files in the current session. For more information, see rehash or Toolbox Path Caching in the "Development Environment" documentation. |
Providing Help for Your Programs | Scripts |