Seperating array by row label

조회 수: 6 (최근 30일)
Erin
Erin 2013년 2월 25일
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.

답변 (1개)

Azzi Abdelmalek
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{:}

카테고리

Help CenterFile Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by