📄 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 + -