summaryrefslogtreecommitdiff
path: root/macros/unshiftdata.sci
blob: 46c3777b848bf339935da9b3e019db06b345d48e (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function y = unshiftdata(x,perm,nshifts)
//Inverts the effect of shiftdata
//Calling sequence
//y=unshiftdata(x,perm,nshifts)
//Parameters
//x
//A vector matrix or n-dimensional array
//perm
//Permutation applied by shiftdata to obtain x
//nshifts
//The number of shifts applied by shiftdata to obtain x
//Description
//y=unshiftdata(x,perm,nshifts)
//Applies the permutation perm or number of shifts nshifts on x to invert shiftdata
//Examples
//x=testmatrix('magi',3)
//x  =
// 
//    8.    1.    6.  
//    3.    5.    7.  
//    4.    9.    2.
//[y,perm,nshifts] = shiftdata(x,2) //Shifts dimension 2
//nshifts  =
// 
//     []
// perm  =
// 
//    2.    1.  
// y  =
// 
//    8.    3.    4.  
//    1.    5.    9.  
//    6.    7.    2.  
//z=unshiftdata(y,perm,nshifts)
//z  =
// 
//    8.    1.    6.  
//    3.    5.    7.  
//    4.    9.    2.
//
//x=1:5
//x  =
// 
//    1.    2.    3.    4.    5.
// [y,perm,nshifts] = shiftdata(x) //Shifts first non-singleton dimension
//nshifts  =
// 
//    1.  
// perm  =
// 
//     []
// y  =
// 
//    1.  
//    2.  
//    3.  
//    4.  
//    5.
////z=unshiftdata(y,perm,nshifts)
//z  =
// 
//    1.    2.    3.    4.    5.
//See Also
//permute
//shiftdata
//Author
//Ankur Mallick
    funcprot(0);
    if(argn(2)<1|argn(2)<2|(argn(2)<3&size(perm)==0)|argn(2)>3)
        error('Incorrect number of input arguments.');
    else
        if(size(perm)==0)
            S=size(x);
            S1=[ones(1,nshifts),S]
            y=matrix(x,S1);
        else
            iperm(perm)=1:length(perm);
            y=permute(x,iperm);
        end
    end
endfunction