c 调用 matlab engine 自定义函数
设置:
1. Tools/Projects and Solutions/VC ++ Directories
Inlcude files: C:\Program Files\MATLAB\R2009a\extern\include
Library files: C:\Program Files\MATLAB\R2009a\extern\lib
2. Property
Configuration Properties/Linker
General: Additional Library Directories: "C:\Program Files\MATLAB\R2009a\extern\lib\win32\microsoft"
Input: Additional Dependencies: libmx.lib libmat.lib libeng.lib
#include
"stdafx.h"
#include
#include
#include
#include
fun_XY.m file
function Z = fun_XY(X,Y)
Z = X*Y;
<stdio.h><stdlib.h><conio.h>"engine.h"
int
main(int argc, char
**argv)
{
double
X[3][2] = {{1,4},{2,5},{3,6}};
double
Y[2][2] = {{1,2},{3,4}};
int
succeedNotFlag = 1;
Engine *ep;
if
(!(ep = engOpen(NULL)))
{
exit(1);
}
engSetVisible(ep,1);
mxArray *xx = mxCreateDoubleMatrix(3,2,mxREAL);
mxArray *yy = mxCreateDoubleMatrix(2,2,mxREAL);
memcpy(mxGetPr(xx),X,6*
sizeof(double
));
memcpy(mxGetPr(yy),Y,4*
sizeof(double
));
engPutVariable(ep,
"X"
,xx);
engPutVariable(ep,
"Y"
,yy);
int
rows = mxGetM(xx);
int
cols = mxGetN(xx);
////succeedNotFlag = engEvalString(ep,"cd D:\\progX\\CM\\mt");
//succeedNotFlag = engEvalString(ep,"path(path,'D:\progX\CM\mt')"); //will not go to the right routine.
succeedNotFlag = engEvalString(ep,
"path(path,'D:\\progX\\CM\\mt')");
////will go to the right routine.
succeedNotFlag = engEvalString(ep,
"Z = fun_XY_lan(X,Y);"
);
mxArray *z_ptr = NULL;
z_ptr = engGetVariable(ep,
"Z"
);
double *z_c = new double
[6];
z_c = (
double
*) mxGetData(z_ptr);
mxDestroyArray(xx);
mxDestroyArray(yy);
delete
[]z_c;
engClose(ep);
return
0;
相关文档:
/*****************test.c****************/
#include <stdio.h>
#include <stdlib.h>
#include "addr.h"
int main()
{
int flag=1;
while(flag)
{
switch(choose_menu())
{
case 1:add_person();break;
case 2:show_person_in ......
在编程的过程中,文件的操作是一个经常用到的问题,在C++Builder中,可以使用多种方法对文件操作,下面我就按以下几个部分对此作详细介绍,就是:
1、基于C的文件操作;
2、基于C++的文件操作;
3、基于WINAPI的文件操作;
4、基于BCB库的文件操作;
5、特殊文件的操作。
壹、基于C的文件操作
在ANSI C中, ......
经过几次面试,发现笔试题基本上都是那几道,没有什么创新或者改变,总结出来给大家参考参考.
一、请填写BOOL , float, 指针变量与“零值”比较的 if 语句。(10分)
请写出 BOOL flag 与“零值”比较的 if 语句。(3分)
标准答案:
if ( flag )
& ......
#include <stdio.h>
#include <string.h>
int
main(void)
{
char str[] =
"3BVPSq4xF.K?=u#,"
"G'K<MrDnRr7gH%#,"
"XKf<f%G`w^=?C<#,"
"HgU_AnNR?*PDQU#,"
......