Seperating array by row label

7 次查看(过去 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