Desktop Tools and Development Environment Previous page   Next Page

Use Existing M-Files and Examples

If you can find existing code that accomplishes what you want to do, copy it and use it in your own M-file, assuming you have legal permission to do so. Following are some resources you can use.

MATLAB and Toolbox M-Files

You can access and reuse the code in most MATLAB and toolbox functions that have a .m file extension. You cannot use MATLAB and toolbox functions that are built-in. They are efficient but their code is not accessible.

If there is a MATLAB function that is similar to what you need to do and it is not built-in, open the file in the Editor/Debugger and use it as a basis for your file. Be sure to save the file using a different name and in a directory that is not in $matlabroot/toolbox. See Saving M-Files for details.

Demos and Examples

MATLAB and its toolboxes include demonstration programs. You can view the code in the demos and copy it for use in your own M-files. To see the demos, type demo, which opens the Help browser to the Demos pane. For more information about demos, see Demos in the Help Browser.

There are also code examples in the online documentation. To see a list of examples for a product, type helpbrowser to open the Help browser. In the Contents pane, click + for a product to view the help topics, and then select the Examples entry.

File Exchange

The MathWorks Web site features a user-contributed code library, from which you can download free M-files contributed by users and developers of MATLAB, Simulink, and related products. To view the files available to download, go to the MATLAB Central File Exchange page on the MathWorks Web site, http://www.mathworks.com/matlabcentral/fileexchange/index.jsp, or access it via the Help -> Web menu in any desktop component.


Previous page  Begin with Existing Code Ways to Edit and Debug M-Files Next page

© 1994-2005 The MathWorks, Inc.