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

回答(1 个)

KSSV
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.
  1 个评论
Ralph
Ralph 2020-8-28
Basically my "x" variable contain 9 samples the loop start from 5 and I want to return all elements before and after 5 so can you please tell me how to return these 9 values in variable j.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by