How to index so end+1 goes to the beginning of an array

20 visualizaciones (últimos 30 días)
Kathleen DiNapoli
Kathleen DiNapoli el 6 de Sept. de 2019
Editada: Stephen23 el 6 de Sept. de 2019
I am trying to index an array so that the index [end +1] refrences the first value in that array rather than the index exceeding array bounds. Is there a simple way to do this in Matlab?

Respuesta aceptada

Stephen23
Stephen23 el 6 de Sept. de 2019
Editada: Stephen23 el 6 de Sept. de 2019
>> V = 1:4;
>> V(1+mod((end+1)-1,end))
ans =
1
>> V(1+mod((end+0)-1,end))
ans =
4
>> V(1+mod((end-1)-1,end))
ans =
3

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by