正在加载图片...
6.1 M-Files MATLAB is an interpretive language, i.e., commands typed at the matlab prompt are interpreted within the scope of the current MATLAB session. However, it is tedious to type in long sequences of commands each time MATLAB is used to perform a task. There are two means of extending MATLAB's power -scripts and functions. Both make use of m-files (named because they have a. m extension and they are therefore also called dot-m files created with a text editor like emacs. The advantage of m-files is that commands are saved and can be easily modified without retyping the entire list of commands 6.1.1 Scripts MATLAB script files are sequences of commands typed with an editor and saved in an m-file To create an m-file using emacs, you can type from Athena prompt athena emacs filename. m or from within matlaB > emacs filename. m Note that"!' allows execution of UNIX commands directly. In the emacs editor, type MATLAB commands in the order of execution. The instructions are executed by typing the file name in the command window at the MATLAB prompt, i. e, the m-file filename.m executed by typing > filename Execution of the m-file is equivalent to typing the entire list of commands in the command window at the MATLAB prompt. All the variables used in the m-file are placed in MAT- LABs workspace. The workspace, which is empty when maTlab is initiated. contains al the variables defined in the matlab session 6.1.2 Functions A second type of m-file is a function file which is generated with an editor exactly as the script file but it has the following general form function Output 1, output 2]= functionname (input1, input2 % l Output 1, output 2]= functionname(input1, input2)Functionname Some comments that explain what the function does go here6.1 M-Files MATLAB is an interpretive language, i.e., commands typed at the MATLAB prompt are interpreted within the scope of the current MATLAB session. However, it is tedious to type in long sequences of commands each time MATLAB is used to perform a task. There are two means of extending MATLAB’s power — scripts and functions. Both make use of m-files (named because they have a .m extension and they are therefore also called dot-m files) created with a text editor like emacs. The advantage of m-files is that commands are saved and can be easily modified without retyping the entire list of commands. 6.1.1 Scripts MATLAB script files are sequences of commands typed with an editor and saved in an m-file. To create an m-file using emacs, you can type from Athena prompt athena% emacs filename.m & or from within MATLAB >> ! emacs filename.m & Note that ‘!’ allows execution of UNIX commands directly. In the emacs editor, type MATLAB commands in the order of execution. The instructions are executed by typing the file name in the command window at the MATLAB prompt, i.e., the m-file filename.m is executed by typing >> filename Execution of the m-file is equivalent to typing the entire list of commands in the command window at the MATLAB prompt. All the variables used in the m-file are placed in MAT￾LAB’s workspace. The workspace, which is empty when MATLAB is initiated, contains all the variables defined in the MATLAB session. 6.1.2 Functions A second type of m-file is a function file which is generated with an editor exactly as the script file but it has the following general form: function [output 1, output 2] = functionname(input1, input2) % %[output 1, output 2] = functionname(input1, input2) Functionname % % Some comments that explain what the function does go here. % 8
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有