Matlab7.0利用mcc與VC++編程執行個體

來源:互聯網
上載者:User

1、啟動MATLAB7,建立m檔案,輸入:

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

儲存檔案為:myfun.m

2、在Matlab 的Command Window 下輸入命令:mcc -B csglsharedlib:mylib myfun 產生動態連結程式庫DLL。Matlab 會產生一系列檔案, 其中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、編譯運行程式。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.