I have an issue where I am getting an error that my subscript indices are wrong, but they are not, and I have many checks to ensure they are not. This code works almost every time, so I don't know why it failed this time.
if (idx - ofs <= 0) || (idx - ofs + slen > length(A)) %skip this iteration if it's too close to the beginning or end
if DEBUGMODE
fprintf('Skipping pulse peak at t = %d\n', pulse_peaks(k));
% keyboard;
end
continue;
end
nonSkipped_iterations = nonSkipped_iterations + 1;
% fprintf('placing the %dth peak - idx=%d\n', k, idx);
s = A( idx + (1:slen) - ofs); %Iterate through A, assign all the values between (idx - ofs + 1) and (idx + slen - ofs) to a new vector
It crashes on s = A( idx + (1:slen) - ofs );
, which when testing using dbstop if error
, I see that idx+(1:slen)-ofs
is a valid array of indices, and is well within the bounds of the length of A.
Is there another reason matlab would complain about subscript indices, but it's showing this error instead?
Edit - the full error is :
Subscript indices must either be real positive integers or logicals.
Error in analyse_stun_gun (line 266)
s = A( idx + (1:slen) - ofs); %Iterate through A, assign all the values between (idx - ofs + 1) and (idx + slen - ofs) to a new vector
Edit : I've somehow lost permission on the server I was working on, I'm working on getting that back, but:
In the offending case :
idx is ~ 10 000
ofs is ~ 5 000
slen is ~ 1 000
length(A) is 1 000 000