MATLAB: Please your help is needed. I have the following 3-D array and would like to sum the values in second column and the third column based on their index values in frist column.

load flow analysismatrix arraymatrix manipulationsum

% |Bus | PGi | QGi |
M = [1 10 0;
1 10 0;
1 76 14.1;
1 76 14.1;
2 10 0;
2 10 0;
2 76 7.0;
2 76 7.0;
7 80 17.2;
7 80 17.2;
7 80 17.2;
13 95.1 40.7;
13 95.1 40.7;
13 95.1 40.7;
15 12 0;
15 12 0;
15 12 0;
15 12 0;
15 12 0;
15 155 0.05;
16 155 25.22;
18 400 137.4;
21 400 108.2;
22 50 -4.96;
22 50 -4.96;
22 50 -4.96;
22 50 -4.96;
22 50 -4.96;
22 50 -4.96;
23 155 31.79;
23 155 31.79;
23 350 71.78];

Best Answer

Since you've got some sort of label attached to the 3 columns of your array, another option to Stephen's answer is to convert the array to a table which is ideally suited for this:
t = array2table(M, 'VariableNames', {'Bus', 'Pgi', 'QGi'})
It is then trivial to calculate the sum per Bus:
varfun(@sum, t, 'GroupingVariables', 'Bus') %apply sum to each variable of the table, grouping by 'Bus'