Coder Error Matlab Function

5 vues (au cours des 30 derniers jours)
ZHAO HONG QIU
ZHAO HONG QIU le 20 Fév 2016
Commenté : Rena Berman le 24 Jan 2017
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 commentaire
Rena Berman
Rena Berman le 24 Jan 2017
(Answers dev) Restored question.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 20 Fév 2016
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.

Catégories

En savoir plus sur MATLAB Coder dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by