BLOCKFUN applies function on sub blocks of an array
Nessuna licenza
BLOCKFUN applies a function on blocks of an array
Y=BLOCKFUN(X,S,funHandle) applies the function funHandle on blocks of size
S on the array X. Y is of size ceil(size(X)./S)
For instance, if X is of size [9 9] and S is [3 3], then
X is partitionned in 9 [3 3] blocks as follow :
| B1 | B4 | B7 |
| B2 | B5 | B8 | where Bi's are [3 by 3] matrices
| B3 | B6 | B9 |
Y is then a [3 by 3] matrix with
Y(i) = fun(Bi(:))
This function is just a simple wrap for accumarray !
See Also : accumarray
EXAMPLES :
rand('twister',12);
x=floor(2*rand(9,9))
x =
0 0 1 1 1 0 0 0 0
1 0 0 0 1 0 0 1 1
0 1 1 1 0 0 0 0 0
1 1 0 1 0 0 1 1 1
0 1 0 0 0 0 0 0 0
1 0 0 0 1 0 0 1 1
1 1 0 1 0 1 1 1 0
0 1 1 1 1 1 1 1 1
1 0 0 1 0 0 0 0 1
y=blockfun(x,[3 3],@sum)
y =
4 4 2
4 2 5
5 6 6
y=blockfun(x,[3 3],@median)
y =
0 0 0
0 0 1
1 1 1
y=blockfun(x,[5 5],@sum)
y =
12 5
11 10
x=floor(2*rand(6,6,6))
y=blockfun(x,[3 2 3],@(x) length(find(x>0))>4)
x=floor(2*rand(512,512,50));
tic; y=blockfun(x,[5 5 5],@sum); toc
Cita come
Mathias Ortner (2025). BLOCKFUN applies function on sub blocks of an array (https://it.mathworks.com/matlabcentral/fileexchange/17000-blockfun-applies-function-on-sub-blocks-of-an-array), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Compatibilità della piattaforma
Windows macOS LinuxCategorie
Tag
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.
Versione | Pubblicato | Note della release | |
---|---|---|---|
1.0.0.0 | Optimized a line, this new (and hopefully last) version is even faster than the previous one. |