swapping elements in matlab?

조회 수: 1 (최근 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에서 Computational Geometry에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by