m file turn CC ++, parameter transmission

xiaoxiao2021-03-06  19

m file turn C / C , parameter transmission

Here, an example shows how to deliver parameters to a transformed M function in the C code and get the return value.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%% Function Result = fork (File, M, A)

INFO = Imfinfo (file); a = imread (file); IMSHOW (a); width = info.width; height = info.HeiGHT;

[m, n] = size (m); asum = 0; for i = 1: m for j = 1: n asum = asum m (i, j); endendasum = asum * a; result = [width, height ASUM]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%

Use this command to compile files:

Mcc -t -wlibhg: forkdll -t link: lib --h libmmfile.mlib libmwsglm.mlib fork

The conversion process and how to join the VC project, please see my "Simplified M file into C / C files, VC compilation". Let's take a look at the code in the VC:

/// CString Str; Str = "C: ///sysfile//simon1//1-a.jpg"; // Select other directory according to your situation MxArray * file = null; file = mxcreateString (Str.getBuffer Str.getLength ())))); // Construct string parameters

Static Double Data [] = {1, 4, 2, 5, 3, 6}; MxArray * m = null; MLFASSIGN (& M, MLFDOUBLEMATRIX (2 / * Rows * /, 3 / * Column * /, Data, NULL / * No imaginary part * /); // Construct matrix parameter // m = [1 2 3; // 4 5 6] // if you want m. ', do this: // mt = mlfctranspose (m);

Double scalar = 10; MxArray * a = null; a = mlfscalar (scalar); // Construct scalar parameters

forkdllinitialize (); // initialization

MxArray * result = null; // Constructs return value

Result = MLFFORK (file, m, a); // call function

Double * hehe = null; hehe = mxgetpr (result); // get back to refer to the address

CString info; info.format ("width =% f length =% f asum =% f", hehe [0], hehe [1], hehe [2]); // acquire each return refer to AFXMessageBox (INFO);

MXDESTROYARRAY (File); // Destroy parameter MXDESTROYARRAY (M); MXDESTROYARRAY (a); MXDESTROYARRAY (HEHE); /// The above example demonstrates how to pass strings, matrices, scales, and more from return fingers Method of variables. The comments in the code are already in detail, I am not explained. For more detailed content in this area, please refer to the reference manual on the official website of Matlab (PDF).

转载请注明原文地址:https://www.9cbs.com/read-42536.html

New Post(0)