MATLAB: Help to find similar variables and add them togeher

similar variables

I have a matrix contains two vectors the first row is time vector in nanosecond and the second row is power vector in micro-watt
X=[0.1 0.3 0.2 0.1 0.4 0.2 0.5 0.9 0.7 0.1 0.4 0.8 0.25 0.2 0.3 0.1; 2 3 5 4 7 13 11 5 12 13 12 14 21 2 17 33]
So the time vector is:
t=[0.1 0.3 0.2 0.1 0.4 0.2 0.5 0.9 0.7 0.1 0.4 0.8 0.25 0.2 0.3 0.1]
and the power vector is:
P=[2 3 5 4 7 13 11 5 12 13 12 14 21 2 17 33]
what I want to do is to find the similar time and add their power together.
for example at the time 0.1 ns we received 2 microwatt then again received 4 mw (in fourth column), 13 mw(in tenth column) and 33 mw (in the last column)
Could you please help me how do this as I have thousands of elements and I need to sort them.
thanks in-advance

Best Answer

If you have the Statistics Toolbox, you can use GRPSTATS:
t=[0.1 0.3 0.2 0.1 0.4 0.2 0.5 0.9 0.7 0.1 0.4 0.8 0.25 0.2 0.3 0.1];
P=[2 3 5 4 7 13 11 5 12 13 12 14 21 2 17 33];
[unique(t)' grpstats(P,t,'sum')]