shake

版本 5.0 (2.2 KB) 作者: Jos (10584)
Randomize a matrix along one dimension
4.0K 次下载
更新时间 2019/2/7

查看许可证

shake - Randomize a matrix along a specific dimension
Y = shake(X) randomizes the order of the elements in each column of the
2D matrix. For N-D matrices it randomizes along the first non-singleton
dimension.

shake(X, DIM) randomizes along the dimension DIM.

[Y, I, J] = shake(X) returns indices so that Y = X(I) and X = Y(J).

Example:
A = [1 2 3 ; 4 5 6 ; 7 8 9 ; 10 11 12] ; % see <SLM> on the FEX ...
B = shake(A, 2) % -> each row is shaked randomly
% 3 2 1
% 6 4 5
% 7 8 9
% 11 10 12%
C = sort(B, 2) % -> equals A!

For vectors V, shake(V) is similar to V(randperm(numel(V)).

The function of shake can be thought of as holding a matrix and shake
in a particular direction (dimension), so that elements are getting
shuffled within that direction only.

引用格式

Jos (10584) (2024). shake (https://www.mathworks.com/matlabcentral/fileexchange/10067-shake), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2018b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Shifting and Sorting Matrices 的更多信息
致谢

启发作品: randone1, RANDSWAP, Permute a grouped vector

Community Treasure Hunt

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

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

updated for newer ML releases, updated algorithm

1.0.0.0

fixed error for scalar inputs