Index exceeds the number of array elements (9).
1 次查看(过去 30 天)
显示 更早的评论
[row,c]=size(x);
total_frames=row/9;
k=1;
i=5;
aa=rem(row,P+1); % in this case P+1=9;
last_index=row-aa;
for i=5:9:last_index %runs for tatal number of samples in signal
x =[x(i)-1, x(i)-2, x(i)-3, x(i)-4, x(i), x(i)+1, x(i)+2, x(i)+3, x(i)+4];
j=x(i);
I want this code to print the above 9 samples in J variable but it throws an error "Index exceeds the number of array elements (9)".
for r=0:(P/2)-1 % Sumation loop from formula
neighbour=x(i + (r-(P/2)));
center=x(i);
if(neighbour > center+ thresh)
b_left(r+1)=1;
elseif( (neighbour > center-thresh) && (neighbour < center+thresh))
b_left(r+1)=0;
elseif (neighbour < center-thresh)
b_left(r+1)=-1;
end
0 个评论
回答(1 个)
KSSV
2020-8-28
The error is simple. You are trying to extract more than the number of elements present in the array.
A = rand(5,1) ;
A(1) % no error
A(5) % no error
A(end) % no error
A(6) % error, because there is no sixth element present in A. Only five elements.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!