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

6 Ansichten (letzte 30 Tage)
Kathleen DiNapoli
Kathleen DiNapoli am 6 Sep. 2019
Bearbeitet: Stephen23 am 6 Sep. 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?

Akzeptierte Antwort

Stephen23
Stephen23 am 6 Sep. 2019
Bearbeitet: Stephen23 am 6 Sep. 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

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by