필터 지우기
필터 지우기

Create cell array from matrix indices

조회 수: 1 (최근 30일)
Dimitris Kokkinos
Dimitris Kokkinos 2014년 4월 17일
댓글: Dimitris Kokkinos 2014년 4월 17일
I have an array nx2.The 1st column has some measurements and the 2nd it's index(corresponds to some year).Example: I need to group the elements of the 1st column according to their index of the second column. I need to take
C{1,1}=[2.25;1.85]
C{2,1}=[2.5;1.9;2.14]
C{3,1}=[3.5;1.79]
C{4,1}=[2.89]
It might be easy for many people, but it's hard to find for me being a rookie.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 17일
편집: Azzi Abdelmalek 2014년 4월 17일
A=[2.25 1;1.85 1;2.5 2;1.9 2;2.14 2;3.5 3;1.79 3;2.89 4]
C=accumarray(A(:,2),A(:,1),[],@(x) {x})
celldisp(C)
  댓글 수: 1
Dimitris Kokkinos
Dimitris Kokkinos 2014년 4월 17일
Thnx for your direct answer Azzi.It works just fine!

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by