diff options
author | Rashpat93 | 2024-08-09 11:47:44 +0530 |
---|---|---|
committer | GitHub | 2024-08-09 11:47:44 +0530 |
commit | af6fe82f90dcb2314a3d37a9a1e297fb0fc447f3 (patch) | |
tree | 80effebb59b2042de6635493f4831ba215f19eee /macros/ipermute.sci | |
parent | b10cff2c07747b039e3c3ee83a34d437e958356b (diff) | |
parent | 2e21edde1c1a251a60739b15e1c699172401f044 (diff) | |
download | FOSSEE-Signal-Processing-Toolbox-af6fe82f90dcb2314a3d37a9a1e297fb0fc447f3.tar.gz FOSSEE-Signal-Processing-Toolbox-af6fe82f90dcb2314a3d37a9a1e297fb0fc447f3.tar.bz2 FOSSEE-Signal-Processing-Toolbox-af6fe82f90dcb2314a3d37a9a1e297fb0fc447f3.zip |
Abinash's Work
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 |