Truncate an array along the dimensions specified

Versión 1.0.0 (2,58 KB) por wfH
A handy function works as the "inverse" of `padarray`. Truncate the ND array in a concise and intuitive fasion.
4 descargas
Actualizado 24 jun 2023

Ver licencia

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

Citar como

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. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2023a
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Etiquetas Añadir etiquetas

Community Treasure Hunt

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

Start Hunting!
Versión Publicado Notas de la versión
1.0.0