MATLAB files and MatLab's Text Editor
MATLAB files are ASCII (American Standard Code for Information Interchange) text-only files that contain Matlab commands and program statements. These files end with an *.m extension. In a later lesson in this module, you will use MATLAB files to define functions. In homeworks, files will be used for executing code to solve problems that do not require much interaction with the user. There are two major types of MATLAB files: function definition files and program scripts.
Matlab includes a text editor that is very useful for creating and editting files. You are not required to use this text editor since it simply creates files in ASCII format (i.e. a "plain text" format). You could use any other text editor such as Microsoft's Notepad. However, Matlab's text editor includes many features that are conducive to MATLAB file creation including syntax highlighting, auto indenting, bracket matching, quote matching, and code searching. Despite the altered appearance the MatLab text editor gives an m-file, the file is always saved in ASCII format.
You can open the MatLab Editor by selecting File->New->Script
,
File->New->Function
or File->Open
(if the file already exists).
button in the upper left of the MatLab menu bar.
Once a function has been defined and its MATLAB file has been saved, you can call/execute/run it from the Command Window by typing the name of the function with arguments (values) in parenthesis after the function name.
>> x = functionNameHere( value1, value2, etc... )
File naming rules
Matlab allows you to name your files using letters, digits, and the underscore character. However, you must start the name with a letter, and may not use blank spaces in the name. Use the underscore character to separate multiple words in your file names.