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

19 views (last 30 days)
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?

Accepted Answer

Stephen23
Stephen23 on 6 Sep 2019
Edited: Stephen23 on 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

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!