Truncate an array along the dimensions specified

버전 1.0.0 (2.58 KB) 작성자: wfH
A handy function works as the "inverse" of `padarray`. Truncate the ND array in a concise and intuitive fasion.
다운로드 수: 4
업데이트 날짜: 2023/6/24

라이선스 보기

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

인용 양식

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. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2023a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0