How can I make smaller matrices (size unknown) from a large matrix?

조회 수: 1 (최근 30일)
John Hunt
John Hunt 2017년 10월 3일
댓글: Cedric 2017년 10월 4일
I have a matrix that has 51 columns and 46999 rows. The 8th column has values 1 to 36. I want to create a matrix for each value in that column (36 total). I want to stack rows that have the same value to make these matrices.
Thus far I know can use a for loop to set up a matrix 36 times then I was trying to use a while loop to "stack" the rows that share the same value in the 8th column, but I can't get that while loop right. Any suggestions?
  댓글 수: 1
John Hunt
John Hunt 2017년 10월 4일
That worked awesome! Thank you, could you explain it a bit so I can understand a bit better whats going on please?

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

채택된 답변

James Tursa
James Tursa 2017년 10월 3일
M = your matrix;
result = cellfun(@(x)M(M(:,8)==x,:),num2cell(1:36),'uni',false);
  댓글 수: 8
Jan
Jan 2017년 10월 4일
+1 for both of you.
@Cedric: Now you know the reason, why I "boost" sometimes. It is for the cases, where the standard voting system is to rough. :-)
Cedric
Cedric 2017년 10월 4일
:-)
It has already been proposed, but I really think that allowing voting for comment would help. This would lead people to add much more value to others' answers by taking time to write well developed comments.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by