RANDBLOCK

版本 1.1.0.0 (2.8 KB) 作者: Jos (10584)
scramble matrices using blocks (v2.3, mar 2011)
3.5K 次下载
更新时间 2011/3/24

查看许可证

RANDBLOCK - randomize blocks of a matrix

R = RANDBLOCK(M,S) randomizes the matrix M by dividing M into non-overlapping blocks of the size specified by S, and shuffling these blocks. M can be a N-D matrix.

The number of elements in S should match the number of dimensions of M, or S can be a scalar specifying a S-by-S-by-S-by ... block size. S should contain positive integers. The size of M in any dimension should be an integer number of times the specified size of the block in that dimension (e.g., if size(M,1) equals 6, S(dim) can be 1,2,3, or 6).

[R,I,J] = RANDBLOCK(...) also returns indices I and J, so that R equals A(I)and R(J) equals A.

M can be a numerical or cell array.

Examples:
% Shuffle blocks of 3 elements of a 15-element vector
M = 1:15 ;
randblock(M,3)

% Scramble a 2D matrix
M = reshape(1:24,4,[]) ;
randblock(A,[3 2]) % randomize the position of the four 3-by-2 blocks
randblock(A,2) % randomize the position of the six 2-by-2 blocks

% Scramble a 3D volume
M = reshape(1:64,[4 8 2]) ;
randblock(A,[2 4 2]) % randomize the position of the four
% 2-by-4-by-2 sub-volumes
% Scramble a cell matrix
M = {'1','a','bb','1c' ; '2a',[3 4 5],'2c','2dd'} ;
randblock(M,[2 2]) % randomize the position of the four 2-by-2 blocks

% Scramble a RGB image Z, and retrieve the original using the
% indices (see the SCREENSHOT)
Z = peaks(200) ; Z = cat(3,Z,flipud(Z), -(circshift(Z.',[100,100]))) ;
Z = (Z - min(Z(:))) ; Z = Z./ max(Z(:)) ;
[Z2,I,J] = randblock(Z,[25,25,size(Z,3)]) ; % Scramble 25-by-25 blocks
subplot(2,2,1) ; image(Z) ; title('Original image') ;
subplot(2,2,2) ; image(Z2) ; title('25x25 scrambled image') ;
subplot(2,2,3) ; image(Z2(J)) ; title('Z2(J) = original image') ;
subplot(2,2,4) ; image(Z(I)) ; title('Z(I) = scrambled image') ;
set (gcf,'Name','[Z2,I,J] = randblock(Z,[25,25,size(Z,3)])') ;

Version 2.3 (mar 2011)

引用格式

Jos (10584) (2025). RANDBLOCK (https://ww2.mathworks.cn/matlabcentral/fileexchange/17981-randblock), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R13
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.1.0.0

modified example in the help

1.0.0.0

repaired minor m-lint warnings in v2.1