Error for the array bounds

I am writing a code to count occurences of successive numbers. Variable r gives the count of the occurences but I am getting an error that the logical indices contain a true value outside the bounds of the array

4 comentarios

Rik
Rik el 5 de Oct. de 2020
What data are you using? When I run the example from Adam I don't get any errors.
Next time post your code as code, not an image. We can't run an image. You should also have posted a comment on the original thread.
The dataset is large. I am using a table T(1048570x542table) and using the code. If the table size is small then it gives value for r but for my case where table size is large it gives the error the logical indices contain a true value outside the bounds of the array
tab=T.Var470
% Length of each group of consecutive 1s
B = diff(find([0;tab(:);0]==0))-1;
B(B==0) = [];
% Index of 1st '1' in each group of consecutive 1s
firstIdx = find(diff([0;tab(:)])==1);
% Row number of the first 1 in groups of 4 or more consecutive 1s
minConsec = 4;
r = firstIdx(B >= minConsec);
Rik
Rik el 5 de Oct. de 2020
Try to write code that will create a tab that triggers the error. You can use rng to make sure the random seed is the same every time the code runs. The only other option is to attach your tab variable in a mat file.
Adam Danz
Adam Danz el 5 de Oct. de 2020
The error is likely due to 1 or more NaN values in the tab vector.
It doesn't make sense to have two different threads on the same topic so I replied in more detail in your original thread. This thread is a duplicate and should probably be closed.

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Preguntada:

el 5 de Oct. de 2020

Comentada:

el 5 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by