MATLAB: Automatically generate new matrices or arrays from unique values in matrix

for loopunique

Hello,
I'm moderately experienced with programming, and I cannot believe how challenging I am finding this hurdle…
Suppose I have the following matrix:
a = [1,1;1,2.5;1,3;2,2;2,2;2,2;3,10;3,11;3,14;3,19;4,9]
and the first column represents a unique site or subject that I need to analyze separately. How can I make, in this case, 4 new matrices or arrays, within the workspace so that I have products that look like this:
site1 = [1,1;1,2.5;1,3]
site2 = [2,2;2,2;2,2]
My real data is more advanced than this, of course, but I cannot seem to figure out how to separate the data into separate sub-data sets based on a unique values. This seems to be a simple problem but I've tried looking at for-loops, the command 'unique', etc. and am getting absolutely nowhere.
Thanks ahead of time,
Ryan

Best Answer

B = accumarray(a(:,1),a(:,2),[],@(x){x})
Using it directly like this, the index will be the leading number. Why you would need to replicate it, I don't know but it could be done easily. I.e:
B=
[3x1 double]
[3x1 double]
[4x1 double]
[ 4]
Thus the first 3x1 could get three ones because it's the first index, etc. Let me know if you need more clarification.
EDIT (from the cyclist): Be sure to see Stephen Cobeldick's comment to this answer, which solves this entirely.