フィルターのクリア

Using i as an index within a loop in Matlab 2016a

1 回表示 (過去 30 日間)
Ken
Ken 2016 年 10 月 5 日
コメント済み: Ken 2016 年 10 月 5 日
Is there a simple, global way to force Matlab 2016 to allow i to be used as a vector index within a loop statement that uses i as the loop index? I've been using i as a convenient index in for loops forever, and the simple assignment statement in the for statement was always sufficient to convert it from it's built in complex type to an integer. i.e.
for i=1:5,
y(i)=stuff;
end;
In Matlab 2016a, this code barfs because i retains its complex definition within the scope of the loop, so can't be used as the index into a vector within the loop. Adding an explicit assignment to an integer e.g. i=0, before the loop, or changing i to another variable name works, but I'd rather not modify every routine that uses i as an index within a loop.
  1 件のコメント
Steven Lord
Steven Lord 2016 年 10 月 5 日
Please show the full, exact text of the error message you receive. The behavior you're describing shouldn't happen and doesn't happen when I use release R2016a or R2016b.
for i = 1:5
y(i) = 23;
end

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

採用された回答

Matthew Eicholtz
Matthew Eicholtz 2016 年 10 月 5 日
I don't know what you mean by "this code barfs". I ran a simple for-loop in MATLAB R2016a with i as the index variable and experienced no barfing.
But, as an aside, because of the complex definition of i, I tend to prefer using ii instead of i in for-loops.
  1 件のコメント
Ken
Ken 2016 年 10 月 5 日
My mistake, sorry to waste your time. This issue was reported by a customer using our code, and I mis-interpreted the symptom working over the phone. Turns out the problem was another difference in later Matlab versions that we were already aware of. Thanks for the thoughtful reply.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by