zoukankan      html  css  js  c++  java
  • Matlab7.0利用mcc与VC++编程实例

    1、启动MATLAB7,新建m文件,输入:

    function myfun(n)
    t
    =0:n;
    y
    =sin(t);
    plot(y);

    保存文件为:myfun.m

    2Matlab Command Window 下输入命令:mcc -B csglsharedlib:mylib myfun 生成动态链接库DLLMatlab 会生成一系列文件, 其中mylib.h mylib.lib mylib.dll mylib.ctf是我们这里需要的。

    3、 在VC++中使用Matlab 生成的动态链接库( *.DLL

    以上面创建的TestDllApp工程为例。将mylib.h mylib.lib mylib.dll mylib.ctf文件拷贝至TestDllApp工程目录下并添加入工程。修改TestDllApp.cpp文件:

    // TestDllApp.cpp : Defines the entry point for the console application.

    //
    #include "stdafx.h"
    #include 
    <stdio.h>
    #include 
    "mylib.h"
    #include 
    "mclmcr.h"

    int opp(int n);
    void main(int argc, char* argv[])
    {
        mylibInitialize();
        
    double x=64;
        mxArray 
    *t;
        t
    =mxCreateDoubleMatrix(1,1,mxREAL);
        memcpy(mxGetPr(t),
    &x,sizeof(double));
        mlfMyfun(t);
        mxDestroyArray(t);
        mylibTerminate();
        printf(
    "This is a test!\n");
        printf(
    "%d\n",opp(16)); 
    }

    int opp(int n){
        
    return n/4*4+4;
    }

    4通过菜单工程/设置,打开工程设置属性页,进入Link页面,在Object/library modules编辑框中,添加文件名libmx.lib libmat.lib libeng.lib

    5、编译运行程序。

  • 相关阅读:
    坑爹的微信支付v3,其实没有那么坑
    Mysql探究之null与not null
    Mysql的空值与NULL的区别
    Java编程思想(第4版) 中文清晰PDF完整版
    URI和URL的区别
    html 文本输入框效果大汇集
    HTTP状态码大全
    Silverlight ModelView中调用UI进程
    appium部分api
    appium元素定位
  • 原文地址:https://www.cnblogs.com/yunbo/p/541236.html
Copyright © 2011-2022 走看看