Coder Error Matlab Function

조회 수: 5 (최근 30일)
ZHAO HONG QIU
ZHAO HONG QIU 2016년 2월 20일
댓글: Rena Berman 2017년 1월 24일
Hi all,
Here is my code
%#eml
function y = m_FFT1(u)
%#codegen
x=u;
Fs=128; %sampling frequency
Ts=1/Fs; %sampling period
N=128; %Sampling point
x=complex(zeros(N,1));
Xre=complex(zeros(N/2,1));
Xim=complex(zeros(N/2,1));
Xre1=complex(zeros(N/2,1));
Xim1=complex(zeros(N/2,1));
sum_all=complex(zeros(N/2,1));
sum_odd=complex(zeros(N/2,1));
sum_even=complex(zeros(N/2,1));
for k=0:N/2-1
% Xre=0; %each one always reset the sum
% Xim=0;
% Xre1=0;
% Xim1=0;
for n=0:N/2-1
%DFT even of x[n]
Xre = Xre+x(2*n+1)*cos(2*pi*k*n/(N/2))/N;
Xim = Xim+x(2*n+1)*(-1j)*sin(2*pi*k*n/(N/2))/N;
%DFT odd of x[n]
Xre1 = Xre1+x(2*n+2)*cos(2*pi*k*n/(N/2))/N;
Xim1 = Xim1+x(2*n+2)*(-1j)*sin(2*pi*k*n/(N/2))/N;
end
sum_even(k+1) = (Xre+Xim);
sum_odd(k+1) = (cos(2*pi*k/N)-1j*sin(2*pi*k/N))*(Xre1+Xim1);
sum_all=(sum_even+sum_odd);
end
y = sum_all;
end
Then display these errors
The right and left hand sides must have the same number of elements.
Function 'm_FFT1' (#44.747.772), line 30, column 6:
"sum_even(k+1) = (Xre+Xim)"
Launch diagnostic report.
Another mistake
The right and left hand sides must have the same number of elements.
Function 'm_FFT1' (#44.781.840), line 31, column 6:
"sum_odd(k+1) = (cos(2*pi*k/N)-1j*sin(2*pi*k/N))*(Xre1+Xim1)"
Launch diagnostic report.
Can anyone help me? Thanks a lot!
  댓글 수: 1
Rena Berman
Rena Berman 2017년 1월 24일
(Answers dev) Restored question.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 2월 20일
You defined
Xre=complex(zeros(N/2,1));
Xim=complex(zeros(N/2,1));
so Xre and Xim must be vectors (unless N=2 that is)
Then you have
sum_even(k+1) = (Xre+Xim);
With the Xre and Xim being vectors, adding the two of them will give a vector. And you are trying to store that vector into sum_even(k+1) which is a single location, a scalar.

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by