Attempted to access A(2); index out of bounds because numel(A)=1

1 回表示 (過去 30 日間)
Brian Aguilar
Brian Aguilar 2016 年 3 月 9 日
コメント済み: Brian Aguilar 2016 年 3 月 9 日
This is the for loop I am trying to use but I keep getting that error message saying
Error, Attempted to access A(2); index out of bounds because numel(A)=1.
How to fix this?
x = 0
for i=1:5
z = x + A(i)*exp(j*phi(i))
x = x + z
end

採用された回答

KSSV
KSSV 2016 年 3 月 9 日
編集済み: KSSV 2016 年 3 月 9 日
numel means the number of elements in a given array/ matrix. You would have given A as a single number, therefore numel(A) = 1. You can access it by A(1). How you can get A(2)? when there is no A(2)?
Any ways in your code above, you have not shown A. According to your loop, A must have 5 elements.
  1 件のコメント
Brian Aguilar
Brian Aguilar 2016 年 3 月 9 日
I got it now, thanks for your help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by