I want change the matlab code to C code with MATLAB Coder!

5 visualizaciones (últimos 30 días)
hyeon woo
hyeon woo el 13 de Nov. de 2023
Editada: Angelo Yeo el 14 de Nov. de 2023
i want to chage the mathlab code to C code with MATLAB coder
I want to solve the IDFT and DFT in C compiler but C compiler no apply complex in exp function.
so i use the MATLAB Coder first time
but I have little problem in Check for Run-Time Issues
function C=IDFT(x)
N=4;
x=[1 2 2 1];
n=0:N-1;
K=0:N-1;
WN=exp(-j*2*pi/N).^n;
for m=1:N
X(m)=sum(x.*WN.^(m-1));
end
df=1/500;
f=df*[0:500];
W=exp(-j*2*pi.*f);
xf=zeros(1,length(f));
for m=1:N
xf=xf+x(m)*W.^(m-1);
end
for m=1:N
x(m)=sum(X.*(WN.^(-1)).^(m-1))/N;
end
and MATLAB Coder return error
line NO 8 Variable 'X' has not been assigned. To assign the variable, use a complete assignment and not a subscript. Code generation does not support creating arrays via indexing.
line NO 15 Cannot assign a complex value into a non-complex location.
How can i do?

Respuestas (1)

Angelo Yeo
Angelo Yeo el 14 de Nov. de 2023
Editada: Angelo Yeo el 14 de Nov. de 2023
Before using MATLAB Coder, there are a few things to check.
  1. The input argument x is assigned internally in line 3. You should remove it.
  2. What's the output of the function IFDT? There is no process to calculate C.
  3. Also, why is x calculated at the end of the function? Wasn't x an input for your function?
  4. What is k in line 5 for?
Regarding the error you encountered, any variables must be explicitly assigned with its type and size when you translate M file into C/C++. This is because C language is not as dynamic as MATLAB. See how to make MATLAB code suitable for C/C++ code generation in the doc below.

Categorías

Más información sobre MATLAB Coder en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!