Sorting and rearranging data in multiple columns

조회 수: 1 (최근 30일)
Rohan Choraghe
Rohan Choraghe 2018년 7월 30일
댓글: Rohan Choraghe 2018년 7월 31일
How to sort data as per ID and rearrange intensities in multiple columns?
ID Internsity >>>> ID1 ID2 ID3
1 23 23 53 44
2 53 78 45 56
3 44 28 12
2 45 26 94
1 78
2 12
3 56
1 28
2 94
1 26
Thanks

채택된 답변

Aquatris
Aquatris 2018년 7월 30일
편집: Aquatris 2018년 7월 30일
One thing is you cannot store 3 columns in first row and 2 columns in others.
Here is a working example of what you want to do, not the most efficient one though;
A = [ 1 23
2 53
3 44
2 45
1 78
2 12
3 56
1 28
2 94
1 26 ]
unq = unique(A(:,1)); % unique elements in 1st column
for i = 1:length(unq)
y{i} = A(A(:,1)==unq(i),2); % find the elements in the 2nd column
% that has the same number in 1st column
end
From here, to get the elements that has "unq(i)" in the first column, you do
y{i}
  댓글 수: 1
Rohan Choraghe
Rohan Choraghe 2018년 7월 31일
Thank you so much Aquatris. It worked perfectly for my huge dataset.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by