how to shuffle a 16*147 matrix?
3 views (last 30 days)
Show older comments
shashwat soni
on 14 Sep 2018
Commented: Image Analyst
on 14 Sep 2018
i have a 16*147 matrix and i want to swap random rows/columns with other random rows/columns, how to do it?
0 Comments
Accepted Answer
Image Analyst
on 14 Sep 2018
Use randperm()
m = reshape(1:30, 5, 6) % Sample data
m(randperm(numel(m))) = m % Scramble/shuffle
m =
1 6 11 16 21 26
2 7 12 17 22 27
3 8 13 18 23 28
4 9 14 19 24 29
5 10 15 20 25 30
m =
16 18 24 7 9 8
3 11 14 28 12 22
27 26 10 30 25 23
29 13 15 20 1 21
19 6 5 4 2 17
3 Comments
Image Analyst
on 14 Sep 2018
It does NOT give a 1-D matrix. You might think so, because you didn't try it and I'm using linear indexing - just one index instead of two. But if you actually try it you'll see:
m = reshape(1:16*147, 16, 147) % Create sample data
m(randperm(numel(m))) = m % Scramble/shuffle it.
whos m
The whos command, as well as the printout to the command window shows it's a 2-D matrix:
Name Size Bytes Class Attributes
m 16x147 18816 double
Linear indexing allows you to access the whole matrix instead of having to scramble rows and columns separately.
More Answers (1)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!