[Scilab-users] Shift indices

Samuel Gougeon sgougeon at free.fr
Thu Nov 9 00:31:27 CET 2017


Le 08/11/2017 à 15:07, Richard llom a écrit :
> Hello,
> is there a function available to shift indices?
> E.g. I have
> aa = [1:10]
> and want
> bb =  6.   7.   8.   9.   10.   1.   2.   3.   4.   5.

If you need to shift i = 1:n indices by /any/ p -- not necessarily n/2 
--, you may do

si = modulo(i+p-1, n)+1    // with n = length(i);

Example:
i = 1:10, p = 2;
si = modulo(i+p-1, length(i))+1
--> i = 1:10, p = 2;
  i  =
    1.   2.   3.   4.   5.   6.   7.   8.   9.   10.

--> si = modulo(i+p-1, length(i))+1
  si  =
    3.   4.   5.   6.   7.   8.   9.   10.   1.   2.

Samuel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20171109/4c0ff617/attachment.htm>


More information about the users mailing list