Seperating array by row label
조회 수: 6 (최근 30일)
이전 댓글 표시
I have a cell array array that's of the from
name data data data data
.
.
.n rows
.
name data data data data
So something like
Apple 1 0 38 1 19 8.9
Carrot -1 4 8 4 3 10
Banana 9 3 1 -45 12 0
Banana 60 1 3 4 58 9
Apple 1 82 28 9 9 -1
Carrot 83 29 1 1 1 0
I'd like to seperate into seperate arrays (or maybe a 3D array), like:
Apple 1 0 38 1 19 8.9
Apple 1 82 28 9 9 -1
Carrot 83 29 1 1 1 0
Carrot -1 4 8 4 3 10
Banana 9 3 1 -45 12 0
Banana 60 1 3 4 58 9
Also, the number of different lables is not known.
댓글 수: 0
답변 (1개)
Azzi Abdelmalek
2013년 2월 25일
편집: Azzi Abdelmalek
2013년 2월 25일
x = {'Apple' [ 1] [ 0] [38] [ 1] [19] '8.9'
'Carrot' [-1] [ 4] [ 8] [ 4] [ 3] [ 10]
'Banana' [ 9] [ 3] [ 1] [-45] [12] [ 0]
'Banana' [60] [ 1] [ 3] [ 4] [58] [ 9]
'Apple' [ 1] [82] [28] [ 9] [ 9] [ -1]
'Carrot' [83] [29] [ 1] [ 1] [ 1] [ 0]}
[a,b,c]=unique(x(:,1))
for k=1:numel(a)
y{k}=x(find(c==k),:)
end
y{:}
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!