フィルターのクリア

How to solve Attempted to access (0) error.?

2 ビュー (過去 30 日間)
Nimisha
Nimisha 2014 年 11 月 22 日
回答済み: Jan 2014 年 11 月 23 日
In attached figure, one equation is there which i need to implement.
where,
x[n] = a* r^n
a = 11; r = 0.9; L = 19; 0<=m<=L; 0<=n<=L
for this i have written a script.
clear all
a = 11;
r = 0.9;
L = 19;
for m = 0:L
for n = 0:L
S(m) = a*(r^n);
end
end
plot(S,m)
xlabel('Value of "S"');
ylabel('Value of "L"');
title('a = 11; r = 0.9; L = 19')
When i run it, it gives following error
Attempted to access (0); index must be a positive integer or logical.
Error in Question_6 (line 8)
S(m) = a*(r^n);
How to solve it..?

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 11 月 23 日
Nimisha - unlike C/C++, indexing into MATLAB arrays begins at one instead of zero. Since your code is iterating (over m) from 0 to L, then the error message makes sense for
S(m) = a*(r^n);
I don't think that you have quite gotten this equation correct. From your attached image, it looks like
S[m] = sum(n=0...m)x[n];
which to me means that your S could be initialized as
a = 11;
r = 0.9;
L = 19;
S = zeros(L+1,1); % size S
S(1) = a*(r^0); % this corresponds to S[0] in your equation
for m = 2:L+1
S(m) = S(m-1) + a*(r^m);
end
Note how the above assumes that S is a recurrence relation. We can then plot it as
plot(S,0:L)
xlabel('Value of "S"');
ylabel('Value of "L"');
title('a = 11; r = 0.9; L = 19')
Try it and see what happens!

その他の回答 (1 件)

Jan
Jan 2014 年 11 月 23 日
When you omit the clear all you can use the debugger to find out the reason of your problem.

カテゴリ

Help Center および File ExchangeDirected Graphs についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by