Filter löschen
Filter löschen

Index exceeds the number of array elements (9).

5 Ansichten (letzte 30 Tage)
Ralph
Ralph am 28 Aug. 2020
Kommentiert: Ralph am 28 Aug. 2020
[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

Antworten (1)

KSSV
KSSV am 28 Aug. 2020
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 Kommentar
Ralph
Ralph am 28 Aug. 2020
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by