[Scilab-users] Shift indices

10 messages
Open this post in threaded view
|

[Scilab-users] Shift indices

 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. This is what I come up with: log_data2 = zeros(log_data); log_data2 = log_data(4001:size(log_data,1),:); log_data2((size(log_data,1)-4000+1):size(log_data,1),:) = log_data(1:4000,:); But I'm wondering if there is a prettier solution? Thanks richard -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Shift indices

 See fftshift -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Shift indices

 In reply to this post by Richard llom Is this solution fine with you? aa = [1:10]; ix =  [6:10,1:5]; bb = aa(ix) Regards, Rafael -----Original Message----- From: users [mailto:[hidden email]] On Behalf Of Richard llom Sent: Wednesday, November 08, 2017 3:08 PM To: [hidden email] Subject: [Scilab-users] Shift indices 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. This is what I come up with: log_data2 = zeros(log_data); log_data2 = log_data(4001:size(log_data,1),:); log_data2((size(log_data,1)-4000+1):size(log_data,1),:) = log_data(1:4000,:); But I'm wondering if there is a prettier solution? Thanks richard -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Shift indices

 In reply to this post by Richard llom 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 _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Shift indices

 In reply to this post by Richard llom 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. > > This is what I come up with: > log_data2 = zeros(log_data); > log_data2 = log_data(4001:size(log_data,1),:); > log_data2((size(log_data,1)-4000+1):size(log_data,1),:) = > log_data(1:4000,:); > > But I'm wondering if there is a prettier solution? n = size(log_data,1); log_data = log_data(modulo((1:n)-2+4001, n)+1, :); Samuel _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Shift indices

 n = size(log_data,1); log_data = log_data([4001:n,1:4000], :); Rafael -----Original Message----- From: users [mailto:[hidden email]] On Behalf Of Samuel Gougeon Sent: Thursday, November 09, 2017 12:06 PM To: Users mailing list for Scilab <[hidden email]> Subject: Re: [Scilab-users] Shift indices 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. > > This is what I come up with: > log_data2 = zeros(log_data); > log_data2 = log_data(4001:size(log_data,1),:); > log_data2((size(log_data,1)-4000+1):size(log_data,1),:) = > log_data(1:4000,:); > > But I'm wondering if there is a prettier solution? n = size(log_data,1); log_data = log_data(modulo((1:n)-2+4001, n)+1, :); Samuel _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Shift indices

 Le 09/11/2017 à 12:42, Rafael Guerra a écrit : > n = size(log_data,1); > log_data = log_data([4001:n,1:4000], :); Yes, it's definitely simpler! (unfortunately, we can't use the implicit polynomial 4001:\$ to replace n=.., 4001:n, because it can't be concatenated) _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Shift indices

 Yes we can, with the one liner solution: log_data = [log_data(4001:\$, :); log_data(1:4000, :)]; Rafael -----Original Message----- From: users [mailto:[hidden email]] On Behalf Of Samuel Gougeon Sent: Thursday, November 09, 2017 2:05 PM To: Users mailing list for Scilab <[hidden email]> Subject: Re: [Scilab-users] Shift indices Le 09/11/2017 à 12:42, Rafael Guerra a écrit : > n = size(log_data,1); > log_data = log_data([4001:n,1:4000], :); Yes, it's definitely simpler! (unfortunately, we can't use the implicit polynomial 4001:\$ to replace n=.., 4001:n, because it can't be concatenated) _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Shift indices

 Thank you all for the replies! This is my solution now: // ======== Wrap around at June 1st ======== ix1 = find(log_date==datenum(log_data(1,3),06,01)) ix2 = [ix1+1:size(log_data,1),1:ix1]; dat2 = log_data(ix2,6); (which is much easier to read :-) -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Shift indices

 In reply to this post by Samuel GOUGEON Dear, this instruction is exactly the one I wanted It allows me on a PELTON 6 jet machine to get a rotating pilot injector Pierre. De : users [mailto:[hidden email]] De la part de Samuel GougeonEnvoyé : jeudi 9 novembre 2017 00:31À : Users mailing list for Scilab <[hidden email]>Objet : Re: [Scilab-users] Shift indices 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 dosi = 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_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users