Truncate an array along the dimensions specified

Version 1.0.0 (2,58 ko) par wfH
A handy function works as the "inverse" of `padarray`. Truncate the ND array in a concise and intuitive fasion.
4 téléchargements
Mise à jour 24 juin 2023

Afficher la licence

I used `padarray`, a built-in function in Image Processing Toolbox, very often.
It was a bit tedious and annoying to turn the padded array into its original size, particularly for ND array.
For example, you might write as follow:
`A = B(1+padsize(1):end-padsize(1), 1+padsize(2):end-padsize(2), 1+padsize(3):end-padsize(3), ......, 1+padsize(k):end-padsize(k));`, which looks messy.
Therefore, I created this handy function as the "inverse" of `padarray` to truncate an array in a concise and intuitive fasion.
The usage mimics `padarray`'s:
`B = truncatearray(A, truncatesize)`
`B = truncatearray(A, truncatesize, direction)`
Examples:
A = rand(randperm(randi([4, 10], 1)));
padsize = randperm(randi([0, ndims(A)], 1));
paddirection= 'pre';
B = padarray(A, padsize, paddirection);
C = truncatearray(B, padsize, paddirection);
if isequal(C, A), disp('Pass'), else, disp('Error');end

Citation pour cette source

wfH (2024). Truncate an array along the dimensions specified (https://www.mathworks.com/matlabcentral/fileexchange/131558-truncate-an-array-along-the-dimensions-specified), MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2023a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Publié le Notes de version
1.0.0