How to circumvent this error: Subscript indices must either be real positive integers or logicals.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
monmatlab
el 20 de Dic. de 2016
Respondida: Jan
el 20 de Dic. de 2016
Assume I have such a vector data=[2 4 5 6 8 3 5 6 7 8 9 …]
I want to set this condition (in addition to other conditions combined with an or )for a function
If data(i)== mod(sum(data((i-12):(i-1))),28)
Obviously I will get for numbers, which indexes are smaller then 13 this error below, but I cannot ignore this numbers since they will have to undergo another condition.
Subscript indices must either be real positive integers or logicals.
Is there a way to circumvent this error? Thank you!
1 comentario
KSSV
el 20 de Dic. de 2016
data((i-12):(i-1)) as you are calling indices subtracted by 12, your i should start with > 12.
Respuesta aceptada
Jan
el 20 de Dic. de 2016
When i is smaller than 13, e.g. 12, the expression
data((i-12):(i-1))
becomes:
data(0:11)
but 0 is an invalid index. So either use
data(max(1, i-12):(i-1))
or decide, what should happen instead. The currently provided information does not allow to guess a replacement, which satisfies your needs.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Numeric Types en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!