# How could I randomly split the columns of a matrix into 3 matrices with equal number of columns?

조회 수: 5 (최근 30일)
gsourop 2018년 10월 22일
편집: Matt J 2018년 10월 22일
Hi everyone,
I would like to ask if there is a way to split a matrix A, with dimensions (100 x 12) into three sub-matrices with dimensions 100 x 4 each. The splitting should be random. For example, sub-matrix B = [A(:,1) A(:,5) A(:,6) A(:,11)], but the elements of the B cannot be included in any of the other sub-matrices. For instance, a potential outcome of sub-matrix C could be C=[A(:,3) A(:,8) A(:,10) A(:,12)] and D=[A(:,2) A(:,4) A(:,7) A(:,9)]. As an extension of the question, ideally, I would like to get different sub-matrices every time I iterate the experiment.

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

### 채택된 답변

Matt J 2018년 10월 22일
편집: Matt J 2018년 10월 22일
Ar=A(:,randperm(12));
submatrix{1}=Ar(:,1:4);
submatrix{2}=Ar(:,5:8);
submatrix{3}=Ar(:,9:12);
##### 댓글 수: 2없음 표시없음 숨기기
gsourop 2018년 10월 22일
편집: gsourop 2018년 10월 22일
The submatrix should be submatrix{3}=Ar(:,9:12), right?
Matt J 2018년 10월 22일
Yes, you're right. I fixed it.

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

### 카테고리

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