HOW TO SORT INTO GROUPS

조회 수: 16 (최근 30일)
Pat
Pat 2011년 9월 17일
I have values
col1 col2
1 9
2 4
3 5
4 6
5 1
6 9
7 0
8 3
9 1
0 2
I WANT TO DIVIDE THIS INTO 5 GROUPS MY OUTPUT IS
1 9 3 5 5 1 7 0 9 1
2 4 4 6 6 9 8 3 0 2
PLEASE CAN ANYONE HELP
  댓글 수: 2
Fangjun Jiang
Fangjun Jiang 2011년 9월 17일
Please format your code and explain what is the grouping.
the cyclist
the cyclist 2011년 9월 17일
Pat, please try to imagine yourself as a reader who knows nothing about your problem. It is impossible to understand what you want to do. Please provide more detail.

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 9월 17일
out = reshape(permute(reshape(a,2,[],2),[1,3,2]),2,[])
  댓글 수: 2
Pat
Pat 2011년 9월 19일
a=[1 9
2 4
3 5
4 6
5 1
6 9
7 0
8 3
9 1
0 2
3 6
3 4
3 7
8 1
8 7
9 2
0 3
4 6
5 7
8 9 ]
i want to divide this data into 5 groups so taht the values in the column 1 and 2 should not change....... have to do this for large data also,can anyone help
Jan
Jan 2011년 9월 19일
@Pat: As mentioned before, it is not clear how the groups are distinguished. I do not see the connection between "The values in the column 1 and 2 should not change" and the example data in your question. Please explain the rule you want to implement.
But you've accepted an answer already. This means, that the posted code solved your problem. Sure?

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

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 9월 17일
a=[1 9
2 4
3 5
4 6
5 1
6 9
7 0
8 3
9 1
0 2 ];
b=mat2cell(a,repmat(2,size(a,1)/2,1),size(a,2));
c=cell2mat(b');
  댓글 수: 2
Jan
Jan 2011년 9월 18일
@Fangjun: Pat asks for 5 groups, but he showed 6 groups. Your code replies a {2 x 10} cell.
Fangjun Jiang
Fangjun Jiang 2011년 9월 18일
I see! Then b or b' should be the outcome.
The OP doesn't seem to be responsive at all based on his history.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by