how to shuffle a 16*147 matrix?

3 views (last 30 days)
i have a 16*147 matrix and i want to swap random rows/columns with other random rows/columns, how to do it?

Accepted Answer

Image Analyst
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
shashwat soni
shashwat soni on 14 Sep 2018
i want a shuffled 16*147 matrix
Image Analyst
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.

Sign in to comment.

More Answers (1)

Matt J
Matt J on 14 Sep 2018
r=randperm(16);
c=randperm(147);
newMatrix=oldMatrix(r,c);

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!