Scilab Home Page | Wiki | Bug Tracker | Forge | Mailing List Archives | Scilab Online Help | ATOMS
File : Details
Login with GitLab

circular shifts circshift cshift()

Circularly shifts elements of a vector, matrix, hypermatrix, cell or structure arrays
(2987 downloads for this version - 4787 downloads for all versions)
Details
Version
2.0
Author
Samuel Gougeon
Maintainer
Samuel Gougeon
Category
License
Supported Scilab Version
Creation Date
May 24, 2015
Description
            
circshift() is now available in Scilab 6.1.0

This version on FileExchange will no longer be maintained.

CHANGES 1.0 => 2.0
------------------
  * usage with arrays of structures was undocumented
  * extension to cell arrays

-->cshift;

 CALLING SEQUENCES:
 cshift;          // displays this help
 R = cshift(M, d) // circularly shifts by d(i) positions components of M 
                  // along its #ith dimensions
 PARAMETERS:
 M,R : vector, matrix or hypermatrix of any data type. Structure or cell arrays
 d   : vector of integers. d(i) is the shift to be applied to the M's 
       components along its #ith dimension.

 EXAMPLES:
 // With a matrix or hypermatrix:
 M = resize_matrix([1 2 ; 3 4 ],[3 3 2]);
 M(1:2,1:2,2) = [5 6 ; 7 8 ]
 cshift(M, 1)
 cshift(M, -1)
 cshift(M, [0 1])
 cshift(M, [1 1])
 cshift(M, [0 1 1])

 // With an array of structures:
 s(4,3).b = %t  ;
 s(2,2).r = %pi ;
 s(3,1).t = "test" ;
 cs = cshift(s,[1, -1])
 cs(1,2).b
 cs(3,1).r
 cs(4,3).t

 // With a cells array:
 c = cell(4,3);
 c(4,3).entries = %t  ;
 c(2,2).entries = %pi ;
 c(3,1).entries = "test"
 cshift(c,[-1,1])

RESULTS
-------
--> M
 M  = 
(:,:,1)
    1.    2.    0.  
    3.    4.    0.  
    0.    0.    0.  
(:,:,2) 
    5.    6.    0.  
    7.    8.    0.  
    0.    0.    0.  
 
--> cshift(M, 1)    // shifts lines by 1 down
 ans  =
(:,:,1) 
    0.    0.    0.  
    1.    2.    0.  
    3.    4.    0.  
(:,:,2)
    0.    0.    0.  
    5.    6.    0.  
    7.    8.    0.  
 
--> cshift(M, -1)   // shifts lines by 1 up
 ans  = 
(:,:,1)
    3.    4.    0.  
    0.    0.    0.  
    1.    2.    0.  
(:,:,2) 
    7.    8.    0.  
    0.    0.    0.  
    5.    6.    0.  
 
--> cshift(M, [0 1])  // shifts columns by 1 right
 ans  =
(:,:,1)
    0.    1.    2.  
    0.    3.    4.  
    0.    0.    0.  
(:,:,2) 
    0.    5.    6.  
    0.    7.    8.  
    0.    0.    0.  
 
--> cshift(M, [1 1])   // shifts lines by 1 down and columns by 1 right
 ans  =
(:,:,1) 
    0.    0.    0.  
    0.    1.    2.  
    0.    3.    4.  
(:,:,2)
    0.    0.    0.  
    0.    5.    6.  
    0.    7.    8.  
 
--> cshift(M, [0 1 1])   //  shift columns by 1 right and pages by 1 forward
 ans  =
(:,:,1)
    0.    5.    6.  
    0.    7.    8.  
    0.    0.    0.  
(:,:,2)
    0.    1.    2.  
    0.    3.    4.  
    0.    0.    0.  
             
Files (2)
[1.95 kB]
Miscellaneous file
Macro

* MAKE IT AVAILABLE in EVERY SESSION: Click here to see HOW TO

* Get help: Enter "cshift" without parameters 

[3.34 kB]
Screenshot
Screenshot of examples
News (0)
Comments (0)
Leave a comment
You must register and log in before leaving a comment.
Login with GitLab
Email notifications
Send me email when this toolbox has changes, new files or a new release.
You must register and log in before setting up notifications.