赋值问题 打印出来的结果 很大很大

hujiayi6022 发布于 2011/10/10 10:49

void Init()
{
MATFile * pMF;  // mat文件
mxArray * pA;  // 矩阵指针

double * pr, * pi, * real, * imag;

// double * pr, * pi ;
int i, j;

real = new double [145*145];
imag = new double [145*145];

pMF = matOpen("c://b.mat", "r"); //注意填写MAT文件位置

pA = matGetVariable(pMF, "b");

pr = mxGetPr(pA);
pi = mxGetPi(pA);

for (i = 0; i < 145; i++)
{
for (j = 0; j < 145; j++)
{
{
real[i * 145 + j] = pr[i * 145 + j] ;
imag[i * 145 + j] = pi[i * 145 + j] ;

// if(real[i * 145 + j] != 0 || imag[i * 145 + j] != 0)
// {
// printf("(%d, %d) %f %f ", j+1, i+1 ,real[i * 145 + j] ,imag[i * 145 + j] ) ;
//  }
}
}
// printf("\n");

} printf("===================================================");

delete [] real;
delete [] imag;

void main() 调用如下

double *real, *imag;   //在调用函数之前定义变量就可以在主函数和子函数中利用了
real = new double [145*145];
imag = new double [145*145];

Init() ;

double *Y1real = new double [145*145];
double *Y1imag = new double [145*145];

for (i = 0; i < 145; i++)
{
for (j = 0; j < 145; j++)

{
//////////////////这里有问题////赋值不成功////////////////////////
Y1real[i * 145 + j] = real[i * 145 + j] ;   //导纳矩阵的实部和虚部
Y1imag[i * 145 + j] = imag[i * 145 + j] ;

// //       printf("%f ",Y1real[i * 145 + j]);  //此处求出的解相当的大
}
printf("\n");
}

// //       printf("%f ",real[i * 145 + j]);  //此处求出的解相当的大

000000000000000000000000000000000000000.000000 -62774385622041925000000000000000
00000000000000000000000000000000000.000000 -627743856220419250000000000000000000
0000000000000000000000000000000.000000 -6277438562204192500000000000000000000000
000000000000000000000000000.000000 -62774385622041925000000000000000000000000000
00000000000000000000000.000000 -627743856220419250000000000000000000000000000000
0000000000000000000.000000 -6277438562204192500000000000000000000000000000000000
000000000000000.000000 -62774385622041925000000000000000000000000000000000000000
00000000000.000000 -627743856220419250000000000000000000000000000000000000000000