| 18 | */ |
| 19 | |
| 20 | void mex_function ( |
| 21 | const matrix<double>& A, |
| 22 | const function_handle& f, |
| 23 | matrix<double>& result |
| 24 | ) |
| 25 | { |
| 26 | // The f argument to this function is a function handle passed from MATLAB. To |
| 27 | // call it we use the following syntax: |
| 28 | call_matlab(f, A, returns(result)); |
| 29 | // This is equivalent to result = f(A). Therefore, the returns(variable) syntax |
| 30 | // is used to indicate which variables are outputs of the function. |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | // Another thing we can do is call MATLAB functions based on their string name |
| 36 | // rather than a function_handle. Here is an example of calling eigs(). |
| 37 | matrix<double> m(2,2); |
| 38 | m = 1,2, |
| 39 | 3,4; |
| 40 | matrix<double> v,d; |
| 41 | |
| 42 | // This is equivalent to [v,d] = eigs(m); |
| 43 | call_matlab("eigs", m, returns(v), returns(d)); |
| 44 | cout << "eigenvectors: \n" << v << endl; |
| 45 | cout << "eigenvalues: \n" << d << endl; |
| 46 | } |
| 47 | |
| 48 | |
| 49 |
nothing calls this directly
no test coverage detected