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

조회 수: 5 (최근 30일)
hyeon woo
hyeon woo 2023년 11월 13일
편집: Angelo Yeo 2023년 11월 14일
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?

답변 (1개)

Angelo Yeo
Angelo Yeo 2023년 11월 14일
편집: Angelo Yeo 2023년 11월 14일
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.

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!