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.