필터 지우기
필터 지우기

matrix - change columns randomly

조회 수: 4 (최근 30일)
Jonny
Jonny 2011년 10월 16일
댓글: Ruchi Agarwal 2020년 1월 7일
Hi, how can I change randomly the positions of entire columns in a matrix [nxm]? For example, I want to change my matrix
A=[ 1 2 3 5 4 ;
2 2 2 2 2 ;
4 5 6 7 7 ;
8 9 8 8 8 ;
9 9 9 9 9 ]; to change into
B=[ 3 5 4 2 1;
2 2 2 2 2;
6 7 7 5 4;
8 8 8 9 8;
9 9 9 9 9];
Thank you :)

답변 (1개)

Wayne King
Wayne King 2011년 10월 16일
A random shuffling of the columns of A. One way:
cols = size(A,2);
P = randperm(cols);
B = A(:,P);
  댓글 수: 1
Ruchi Agarwal
Ruchi Agarwal 2020년 1월 7일
how to restore original columns after randperm?

댓글을 달려면 로그인하십시오.

카테고리

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