Đang chuẩn bị liên kết để tải về tài liệu:
matlab primer 7th edition phần 4

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

đầu vào hoặc đầu ra, mặc dù. Các chức năng mexPrintf chỉ là tương tự như printf. Bạn cũng có thể sử dụng printf bản thân, lệnh mex định nghĩa lại nó như là mexPrintf khi chương trình được biên soạn với một # xác định. Bằng cách này, bạn có thể viết một thói quen | mxArray . This hello.c MEX-file does not have any inputs or outputs though. The mexPrintf function is just the same as printf. You can also use pri ntf itself the mex command redefines it as mexPrintf when the program is compiled with a define. This way you can write a routine that can be used from MATLAB or from a stand-alone C application without MATLAB. 9.2 C versus MATLAB arrays MATLAB stores its arrays in column major order while the convention for C is to store them in row major order. Also the number of columns in an array is not known until the mexFunction is called. Thus two-dimensional arrays in MATLAB must be accessed with onedimensional indexing in C see also Section 5.6 . In the example in the next section the INDEX macro helps with this translation. Array indices also appear differently. MATLAB is written in C and it stores all of its arrays internally using zero-based indexing. An m-by-n matrix has rows 0 to m-1 and columns 0 to n-1. However the user interface to these arrays is always one-based and index vectors in MATLAB are always one-based. In the example below one is added to the List array returned by diagdom to account for this difference. 9.3 A matrix computation in C In Chapters 7 and 8 you wrote the function ddom.m. Here is the same function written as an ANSI C MEX-file. Compare the diagdom routine with the loop-based 55 version ddomloops.m in Section 8.6. MATLAB mx and mex routines are described in Section 9.4. include mex.h include matrix.h include stdlib.h include float.h define lNDEX i j m i j m define ABS x x 0 x - x define MAX x y x y x y void diagdom double A int n double B double tol int List int nList double d a f bij bii int i j k for k 0 k n n k B k A k _ if tol 0 _ tol 100 DBL_EPSILON k 0 for i 0 i n i . d B INDEX i i n a ABS d f 0. I for j 0 j n j . if i j . _ __. bij B INDEX i j n f ABS bij if f a List k i bii 1 tol MAX f tol if d 0 56 bii -bii B INDEX i i n bii . nList k void error char s mexPrintf Usage B i diagdom A tol