Attempted to access y(2); index out of bounds because numel(y)=1. Error in ==> dft at 9 z(k)=y(k)+​y(i)*(exp(​-i*2*pi/n)​^k*i);

1 回表示 (過去 30 日間)
vinay teja
vinay teja 2014 年 8 月 13 日
編集済み: Andrei Bobrov 2014 年 8 月 13 日
this is the code i'm working out but i'm getting some errors pls help in in solving this...
clc
clear all
close all
x=input('enter x:')
n=length(x)
for k=1:n
y(k)=0
for i=1:n
z(k)=y(k)+y(i)*(exp(-i*2*pi/n)^k*i);
end
end
z

回答 (1 件)

Julia
Julia 2014 年 8 月 13 日
編集済み: Julia 2014 年 8 月 13 日
Hi,
You do not define the size of y (I guess the same size as x). So you get for k=1 y(1) but try to access y(2), y(3), ... , y(n) in the second for loop. k stays 1 while i increases. Preallocating the size of y should solve your problem.
>> x = [1 2 3 4]
x =
1 2 3 4
>> y=zeros(1,length(x))
y =
0 0 0 0

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by