Seperating array by row label

6 views (last 30 days)
Erin
Erin on 25 Feb 2013
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.

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 25 Feb 2013
Edited: Azzi Abdelmalek on 25 Feb 2013
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{:}

Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!