blob: 3717cd384faa95a0c22f70e034a87f9d2ef1282c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
function R = circshift(M,d)
// Shifts array circularly
// CALLING SEQUENCES:
// R = circshift(M, d)
// circularly shifts by d(i) positions components of M along its #ith dimensions
// PARAMETERS:
// M,R : vector or matrix of any data type
// d : vector of integers. d(i) is the shift to be applied to the M's components
// along its ith dimension.
// for example d = [0 n] will shift element n position along column
// EXAMPLES:
// M = [1 2 3 4];
// circshift(M, [0 1])
//Output :
// ans =
//
// 4. 1. 2. 3.
if argn(2)==0
error("Invalid input")
R = []
return
end
s = size(M)
R = M
for i=1:length(d)
if s(i)>1
D = pmodulo(d(i),s(i))
if D~=0
S = emptystr(1,length(s))+":"
S(i) = "[s(i)-D+1:s(i) 1:s(i)-D]"
S = strcat(S,",")
if typeof(R) ~= "ce"
execstr("R = R("+S+")")
else
execstr("R.entries = R("+S+").entries")
end
end
end
end
endfunction
|