tailieunhanh - Learning MATLAB Version 6 (Release 12) phần 6

Dòng đầu tiên của một chức năng M-file bắt đầu với chức năng từ khóa. Nó cung cấp cho các tên chức năng và trình tự lập luận. Trong trường hợp này, có đến hai đối số đầu vào và một trong tham số đầu ra. Các dòng tiếp theo, dòng trống hoặc thực thi đầu tiên, là những dòng bình luận rằng cung cấp các văn bản trợ giúp. Những dòng này được in khi bạn gõ | Scripts and Functions You can see the file with type rank Here is the file. function r rank A tol RANK Matrix rank. RANK A provides an estimate of the number of linearly independent rows or columns of a matrix A. RANK A tol is the number of singular values of A that are larger than tol. RANK A uses the default tol max size A norm A eps. s svd A if nargin 1 tol max size A max s eps end r sum s tol The first line of a function M-file starts with the keyword function. It gives the function name and order of arguments. In this case there are up to two input arguments and one output argument. The next several lines up to the first blank or executable line are comment lines that provide the help text. These lines are printed when you type help rank The first line of the help text is the H1 line which MATLAB displays when you use the lookfor command or request help on a directory. The rest of the file is the executable MATLAB code defining the function. The variable s introduced in the body of the function as well as the variables on the first line r A and tol are all local to the function they are separate from any variables in the MATLAB workspace. This example illustrates one aspect of MATLAB functions that is not ordinarily found in other programming languages - a variable number of arguments. The rank function can be used in several different ways. rank A r rank A r rank A 6-19 6 Programming with MATLAB Many M-files work this way. If no output argument is supplied the result is stored in ans. If the second input argument is not supplied the function computes a default value. Within the body of the function two quantities named nargin and nargout are available which tell you the number of input and output arguments involved in each particular use of the function. The rank function uses nargin but does not need to use nargout. Global Variables If you want more than one function to share a single copy of a variable simply declare the variable as global in all the

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.