labwindows/cvi与matlab联合编程
本人变了一个程序,用labwindows/cvi调用matlab以解决小波去除噪声问题。程序运行后,能够正常启动matlab,并将其最小化,但是无法从labwindows/cvi——matlab传递数组。程序如下》#include "Matlabsrvr.h"
#include "MATLABUtil.h"
#include <ansi_c.h>
#include <analysis.h>
#include <cvirte.h>
#include <userint.h>
#include "小波分析.h"
#include <utility.h>
#include <formatio.h>
static int panelHandle;
static CAObjHandle hMATLAB=0;
double *wave;
double *Noise;
double *PrimitiveWave;
int i;
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "小波分析.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK DispPrimitGRAPH (int panel, int control, int event, //用来显示波形,并且能正常显示
void *callbackData, int eventData1, int eventData2)
{
double phase,f;
switch (event)
{
case EVENT_COMMIT:
phase=0;
f=1.0/256;
Noise=malloc(1024*sizeof(double));
WhiteNoise(1024,1,1,Noise);
PrimitiveWave =malloc(1024*sizeof(double));
wave=malloc(1024*sizeof(double));
SineWave(1024,1,f,&phase, PrimitiveWave);
for(i=0;i<1024;i++)
wave= PrimitiveWave+Noise;
DeleteGraphPlot (panelHandle, PANEL_PGRAPH, -1, VAL_IMMEDIATE_DRAW);
PlotY (panelHandle, PANEL_PGRAPH, wave, 1024, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
break;
}
return 0;
}
int CVICALLBACK ExecuteFilter (int panel, int control, int event,//在另一个图形窗空中显示去除噪声后的波形
void *callbackData, int eventData1, int eventData2)
{
HRESULT stat; /*定义matlab打开状态*/
double *matrixReal=NULL;
double *matrixImag=NULL;
unsigned dim1=2;
unsigned dim2=2;
double a;
int result=0;
LPSAFEARRAY saReal=NULL;
LPSAFEARRAY saImag=NULL;
switch (event)
{
case EVENT_COMMIT:
stat=MLApp_NewDIMLApp (NULL, 1, LOCALE_NEUTRAL,0, &hMATLAB);
MinMaxMATLAB(hMATLAB,0);//能够正常欲行
for(i=0;i<1024;i++)
a=wave;
result=SendMatrix(hMATLAB,"a",(double*)a,NULL,1,1024);//矩阵发送不成功
if (result!=SUCCESS)
{
MessagePopup("ERROR","Error in sending Matrix to matlab");
return 0;
}
result=RunMATLABCommand(hMATLAB,"xd=wden(a,'heursure','s','one',8,'sym8');");
if (result!=SUCCESS)
{
MessagePopup("ERROR","Error in sending command to matlab");
return 0;
}
result=GetMatrix(hMATLAB,"xd",&matrixReal,&matrixImag,&dim1,&dim2);
if (result!=SUCCESS)
{
MessagePopup("ERROR","Error in Getting Matrix from matlab");
return 0;
}
DeleteGraphPlot (panelHandle, PANEL_FGRAPH, -1, VAL_IMMEDIATE_DRAW);
PlotY (panelHandle, PANEL_FGRAPH, matrixReal, 1024, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
break;
}
return 0;
}
int CVICALLBACK close (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
页:
[1]