swapping elements in matlab?

2 次查看(过去 30 天)
Eric
Eric 2013-12-17
回答: Suneesh 2013-12-17
How would I swap elements randomly in matlab? E.G I have a matrix M=Randi(3,10); and I want to swap its elements/cells around randomly.

采纳的回答

Suneesh
Suneesh 2013-12-17
M=randi(3,10);
M can then be linear indexed by the set [1,30] since there are 30 elements. So you could get a RANDom PERMnutation of that by using RANDPERM.
idx = randperm(30)
Then
Mnew = M([idx]);
and shape up Mnew
Mnew = reshape(Mnew,3,10)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by