next up previous contents
Next: Script and Data Files Up: The Session Previous: Shell Escapes



An m-file is a plain text file (created with your favorite text editor) in a format MATLAB understands. They must end in .m or MATLAB won't accept them. Experience shows (but documentation is silent on) that m-file names may not have periods in them other than the .m, nor may they have any hyphens (apparently MATLAB wants to think they're minuses). Underscores are acceptable.

Any m-files in any directory in your path (see gif Paths) can be used, as can m-files in the current directory. Use clash to test if your m-file name will collide with an existing one.

M-files can reference each other and themselves recursively.

To see what an m-file says, type file.m. This works for MATLAB's built-in m-files as well as for those you create. Use what directoryname or help directoryname to see what m-files (and mat-files and mex-files) are available; what by itself looks in the current directory. exist('thingy') will return zero if thingy is undefined, and nonzero otherwise; the exact value specifies the nature of thingy (see help exist). See gif Paths about where MATLAB will look for m-files.

In theory, MATLAB only loads in an m-file script or function the first time you refer to it; it caches the contents and refers to the contents thereafter. This would mean changes in the file would not affect MATLAB's actions. In practice, MATLAB (at least on Athena) does read the m-file each time, and uses the cache only if it can no longer find the m-file in question. To force MATLAB to reread the file, use clear(filename) to remove the cached meaning.

If all you want to do is supply some data, see gif Building Matrices.

Sat Mar 21 21:42:28 EST 1998