フィルターのクリア

Attempted to access cols3(6); index out of bounds because numel(cols3)=5

2 ビュー (過去 30 日間)
Paola
Paola 2017 年 10 月 3 日
編集済み: Guillaume 2017 年 10 月 3 日
Hello, I get an error when I run my code. This is the part that gives me prob. Actually, the length of cols3 in my data can vary depending on the data set I am using. In this specific example, the real length of cols3 is 5.
for i=1:length(cols3)
dat{i}=newdata(1:6,cols3(i):cols3(i+1));
end
  2 件のコメント
KSSV
KSSV 2017 年 10 月 3 日
What is newdata? Here is the problem.
Paola
Paola 2017 年 10 月 3 日
newdata is a 6XN matrix. The above is not the complete code. Actually the whole code doesn't give me errors. Only when I add this "for" at the end...

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

採用された回答

Guillaume
Guillaume 2017 年 10 月 3 日
Well, yes your code is never going to work, you set i to iterate from 1 to the numbers of elements in cols3, yet you access cols3(i+1). When i is equal to the index of the last element then cols3(end+1) is not valid.
One possible way to fix this may be to stop at the end-1:
for i = 1 : numel(cols3)-1 %numel is safer than length

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by