Need help in creating a script without using for loops.

조회 수: 1 (최근 30일)
matthew choo
matthew choo 2020년 9월 25일
댓글: matthew choo 2020년 9월 25일
I am trying to write a scrpt without using for loops. Attach is the scripts with for loops. They are for Q3a and Q3b.
  댓글 수: 4
KSSV
KSSV 2020년 9월 25일
Don't show your image as a image snippet....copy your code here.
matthew choo
matthew choo 2020년 9월 25일
%Biosensor Project 2 Q3
%Develop a function in MatLab to
%Calculate the Discrete Fourier Transform
%Check the function with the function in Matlab.
%Develop a function. Don't use loop.
%Implement function with matrices.
%To test function using following signals.
%a)Aperiodic signal
%x[n]={0,1,2,3,4,3,2,1,0,0,0,0}
x=[0 1 2 3 4 3 2 1 0 0 ]
l=length(x)
disp('array initialized with zero and length l')
for k=1:10
xk(k)=0;
for n=1:10
xk(k)=xk(k)+x(n)*k;
end
end
disp('displaying final transform')
disp(xk)
%function [Xk] = dft(xn)
%x=[0 1 2 3 4 3 2 1 0 0 ]
%len = length(xn);
%w = 2*pi*linspace(0,1-1/len,len);
%Xk = exp(-1j*w'*(n-1))*xn';

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

답변 (1개)

David Hill
David Hill 2020년 9월 25일
N=length(x);
Xk=sum(x.*exp((-1i*2*pi/N*(0:N-1)).*(0:N-1)'),2);

태그

Community Treasure Hunt

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

Start Hunting!

Translated by