diff options
author | Abinash Singh | 2024-08-08 16:31:44 +0530 |
---|---|---|
committer | Abinash Singh | 2024-08-08 16:33:51 +0530 |
commit | 1a3caa688450fd49135a1777418c7370e15bb72d (patch) | |
tree | 99447e3e11591651bbb160855fece4e7d82ffc77 /macros/ipermute.sci | |
parent | f8ae45ed71b709b3308a472ca00d641d6ba0fda3 (diff) | |
download | FOSSEE-Signal-Processing-Toolbox-1a3caa688450fd49135a1777418c7370e15bb72d.tar.gz FOSSEE-Signal-Processing-Toolbox-1a3caa688450fd49135a1777418c7370e15bb72d.tar.bz2 FOSSEE-Signal-Processing-Toolbox-1a3caa688450fd49135a1777418c7370e15bb72d.zip |
Imlemented by Abinash Singh During FOSSEE Semester Long Fellowship 2024
Diffstat (limited to 'macros/ipermute.sci')
-rw-r--r-- | macros/ipermute.sci | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/macros/ipermute.sci b/macros/ipermute.sci new file mode 100644 index 0000000..ed78383 --- /dev/null +++ b/macros/ipermute.sci @@ -0,0 +1,25 @@ +/* +Description + The inverse of the permute function. + The expression + ipermute (permute (A, perm), perm) + returns the original array A. +Calling Sequence + ipermute (A, iperm) +*/ +function B = ipermute(A, perm) + // ipermute : Inverse permute the dimensions of a matrix A. + // B = ipermute(A, perm) returns the array A with dimensions inverted + // according to the permutation vector `perm`. + // Validate the permutation vector + if max(size(perm)) ~= ndims(A) || or(gsort(perm, "g", "i") ~= 1:ndims(A)) + error('Permutation vector must contain unique integers from 1 to ndims(A).'); + end + // Compute the inverse permutation vector + invPerm = zeros(size(perm,1),size(perm , 2)); + for i = 1:max(size(perm)) + invPerm(perm(i)) = i; + end + // Use the permute function with the inverse permutation + B = permute(A, invPerm); +endfunction |