I want change the matlab code to C code with MATLAB Coder!
Afficher commentaires plus anciens
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?
Réponses (1)
Angelo Yeo
le 14 Nov 2023
Modifié(e) : Angelo Yeo
le 14 Nov 2023
0 votes
Before using MATLAB Coder, there are a few things to check.
- The input argument x is assigned internally in line 3. You should remove it.
- What's the output of the function IFDT? There is no process to calculate C.
- Also, why is x calculated at the end of the function? Wasn't x an input for your function?
- 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.
Catégories
En savoir plus sur 변환 dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!