MATLAB: In a cell how to extract a specific range of values from a few columns that have a certain value in another column

cellcell arraycell arrayscell to structmatrixmatrix manipulationstructstructures

I'm quite new to MATLAB so apologies if my question is a bit confusing.
I have a cell with subject names in the first column, time points in the second column and experiment values in the third column:
Bob 1 100
Bob 3 200
Bob 4 500
Bill 1 200
Bill 2 300
Bill 5 600
I want to create a struct with 2 fields using this cell; the first with the subjects name and the second field with a matrix that has the time and experiment values for that subject. For example, for the above cell I want it to make a 1×2 struct with 2 fields with the first entry being:
Name: 'Bob'
Values: [1,100 ; 3,200 ; 4,500]
And the seecond entry in the struct being:
Name: 'Bill'
Values: [1,200 ; 2,300 ; 5,600]

Best Answer

This method will correctly preserve the order of the input data:
C = {...
'Bob',1,100;
'Bob',3,200;
'Bob',4,500;
'Bill',1,200;
'Bill',2,300;
'Bill',5,600;
'Bob',8,1000;
'Anna',2,900;
'Anna',9,000;
};
[uni,idx,idy] = unique(C(:,1),'stable');
mat = cell2mat(C(:,2:3));
[idy,idz] = sort(idy);
tmp = accumarray(idy,idz,[],@(r){mat(r,:)});
S = struct('name',uni,'values',tmp)
And checking:
for k = 1:numel(S) S(k).name S(k).values end
prints:
ans =
Bob
ans =
1 100
3 200
4 500
8 1000
ans =
Bill
ans =
1 200
2 300
5 600
ans =
Anna
ans =
2 900
9 0