Effacer les filtres
Effacer les filtres

Error "assignment to expression with array type" when using C script to handle complex number with mex.

22 vues (au cours des 30 derniers jours)
Initialize pointer
/*Input variables*/
double *kloc_r;
double *kloc_i;
double *img_r;
double *img_i;
Assign the complex numbers to array my_plan.f_hat[] whose element's type is double complex.
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
double real = img_r[(j*row + i)];
double imag = img_i[(j*row + i)];
my_plan.f_hat[(j*row + i)] = real +_Complex_I*imag;
}
}
Assign double numbers to array my_plan.x[] whose element's type is double.
for(j = 0; j < my_plan.M_total; j++){
my_plan.x[2*j + 0] = kloc_r[j];
my_plan.x[2*j + 1] = kloc_i[j];
}
When compiling, it alerts me with following error.
error: assignment to expression with array type: my_plan.f_hat[(j*row + i)] = real +_Complex_I*imag;
Source Code
#include "mex.h"
#include "nfft3.h"
#include <stdio.h>
#include <stdlib.h>
#include <complex.h>
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]){
if(nrhs!=2){
mexErrMsgTxt("Usage: res = nfft(kloc, img)");
return;
}
/*Input variables*/
double *kloc_r;
double *kloc_i;
double *img_r;
double *img_i;
/*Output variables*/
double *kval_r;
double *kval_i;
/*Initialization*/
kloc_r = mxGetPr(prhs[0]);
kloc_i = mxGetPi(prhs[0]);
img_r = mxGetPr(prhs[1]);
img_i = mxGetPi(prhs[1]);
plhs[0] = mxCreateDoubleMatrix(mxGetM(prhs[0]),
mxGetN(prhs[0]), mxCOMPLEX);
kval_r = mxGetPr(plhs[0]);
kval_i = mxGetPi(plhs[0]);
int i, j;
int row = mxGetM(prhs[1]);
int col = mxGetN(prhs[1]);
int M = mxGetM(prhs[0]) * mxGetN(prhs[0]);
/* two dimensional nfft */
nfft_plan my_plan;
nfft_init_2d(&my_plan, row, col, M);
/*Get image(time domain)*/
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
my_plan.f_hat[(j*row + i)] = img_r[(j*row + i)] +
_Complex_I*img_i[(j*row + i)];
}
}
/*Get k-space trajectory*/
for(j = 0; j < my_plan.M_total; j++){
my_plan.x[2*j + 0] = kloc_r[j];
my_plan.x[2*j + 1] = kloc_i[j];
}
if(my_plan.flags & PRE_PSI)
nfft_precompute_psi(&my_plan);
/*Apply transform*/
nfft_trafo(&my_plan);
/*Output k value*/
for(j = 0; j < my_plan.M_total; j++){
kval_r[j] = creal(my_plan.f[j]);
kval_i[j] = cimag(my_plan.f[j]);
}
nfft_finalize(&my_plan);
}
Error
  2 commentaires
James Tursa
James Tursa le 26 Jan 2018
Please post the code for the definition of the variables involved. Also, please do NOT post screen shots of code. We can't run screen shots. Please replace your screen shots with actual text that you highlight and use the "{ } Code" button to format.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by