MATLAB: Somebody plz help me with this code. I got an error after run this code is subscript indices must either be real positive integers or logical.

subscript indices must either be real positive integers or logical.

for i=1:length(left);
[R_A(i) R_t(i)]=max(sigL(left(i):raight(i)));
R_t(i)=R_t(i)-1+left(i) %add offset
[Q_A(i) Q_t(i)]=min(sigL(left(i):R_t(i)));
Q_t(i)=Q_t(i)-1+left(i)
[S_A(i) S_t(i)]=min(sigL(left(i):raight(i)));
S_t(i)=S_t(i)-1+left(i)
[P_A(i) P_t(i)]=max(sigL(left(i):Q_t(i)));
P_t(i)=P_t(i)-1+left(i)
[T_A(i) T_t(i)]=max(sigL(S_t(i):raight(i)));
T_t(i)=T_t(i)-1+left(i)+47;
end

Best Answer

%your code:
left=find(difsig==1);
raight=find(difsig==-1);
So left and the mispelled raight are a vector of indices of difsig. They're positive integers that can be any value from 1 to numel(difsig),
%[...]

left=left-(6+16);
raight=raight-(6+16);
From these positive integers you then subtract 10, so they're now integers from -9 to numel(difsig)-9,
%[...]
[R_A(i) R_t(i)]=max(sigL(left(i):raight(i)));
which you're now using as indices. Clearly, there's a problem here since if left or the mispelled raight are less than 1, they can't be used to index.
Unfortunately, the comments don't really explain what you're trying to do, so it's difficult to tell you how to fix it other thanmaking sure that the indices you generate can't be less than 1.