Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.“2”
14 ビュー (過去 30 日間)
古いコメントを表示
I keep getting this error, my desired output is to get abs(I(2,ii(a))-I(2,ii(a)-1) so that when ii(a)=2, I want I(2,2) minus I(2,1) which is 5.1 minus 5.0 : Index expression out of bounds. Attempted to access element 2. The valid range is 1-1."2".
The error is due to this line:
arr(1,ii(a)) = arr(1,ii(a)) + abs(I(2,ii(a))-I(2,ii(a)-1));.
I define I as the following in .mat file:
save data -v7.3 'I' load('data.mat','I');
I =
Columns 1 through 6
0 1.0000 2.0000 3.0000 4.0000 5.0000
5.0000 5.1000 5.2000 5.2000 5.5000 5.9000
Column 7
6.0000
6.0000
回答 (1 件)
Azzi Abdelmalek
2013 年 11 月 8 日
Check the sizes of ii and I, check also if all values in ii are positive integer
8 件のコメント
Azzi Abdelmalek
2013 年 11 月 8 日
there are some problems in your code
function arr= fcn(I,count,oldval) % I is not used in your code
aa=zeros(2,5); this line is unnecessary, because just after you wrote also aa=load('data.mat','I'); in this case the result is a structure array named aa with field I , note that I has nothing to do with I in function argument. to get the value
aa=aa.I
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!