?? mrandwin.c
字號:
#include <stdio.h>
#include <math.h>
#include "matlab.h"
#include <windows.h>
#define MAXCMDTOKENS 128
/*調用由mrandplot.m生成的 C語言函數*/
extern mxArray * mlfMrandplot( mxArray * );
static int totalcnt = 0;
static int upperlim = 0;
static int firsttime = 1;
char *OutputBuffer;
void WinPrint( char *text )
{
int cnt;
if (firsttime)
{
OutputBuffer = (char *)mxCalloc(1028, 1);
upperlim += 1028;
firsttime = 0;
}
cnt = strlen(text);
if (totalcnt + cnt >= upperlim)
{
char *TmpOut;
TmpOut = (char *)mxCalloc(upperlim + 1028, 1);
memcpy(TmpOut, OutputBuffer, upperlim);
upperlim += 1028;
mxFree(OutputBuffer);
OutputBuffer = TmpOut;
}
strncat(OutputBuffer, text, cnt);
}
void WinFlush(void)
{
MessageBox(NULL, OutputBuffer, "MRANDDATA", MB_OK);
mxFree(OutputBuffer);
}
WINAPI WinMain( HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow )
{
LPSTR argv[MAXCMDTOKENS];
int argc = 0;
mxArray *N; /* mrandplot的輸入參數 */
mxArray *R; /* mrandplot的輸出參數 */
int n;
MrandplotLibInitialize(); /* 初始化由mrandplot.m生成的 靜態鏈接庫*/
mlfSetPrintHandler(WinPrint);
/* 得到命令行參數 */
argv[argc] = "mrandplot.exe";
argv[++argc] = strtok(lpszCmdLine, " ");
while (argv[argc] != NULL) argv[++argc] = strtok(NULL, " ");
if (argc >= 2)
{
n = atoi(argv[1]);
}
else
{
n = 20;
}
/* 創建mlfMrandplot函數的輸入參數 */
N = mxCreateDoubleMatrix(1, 1, mxREAL);
*mxGetPr(N) = n;
/*調用由mrandplot.m編譯的mlfMrandplot函數*/
R = mlfMrandplot(N);
/* 輸出結果 */
mlfPrintMatrix(R);
WinFlush();
/* 釋放分配mxArray MATLAB 陣列變量 */
mxDestroyArray(N);
mxDestroyArray(R);
/*終止由mrandplot.m生成的 靜態鏈接庫*/
MrandplotLibTerminate();
return(0);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -