lundi 27 février 2017

How can the AVERAGEIFS function be translated into MATLAB?

I am working at moving my data over from Excel to Matlab. I have some data that I want to average based on multiple criteria. I can accomplish this by looping, but want to do it with matrix operations only, if possible.

Thus far, I have managed to do so with a single criterion, using accumarray as follows:

data=[
    1 3
    1 3
    1 3
    2 3
    2 6
    2 9];

accumarray(data(:,1),data(:,2))./accumarray(data(:,1),1);

Which returns:

3
6

Corresponding to the averages of items 1 and 2, respectively. I have at least three other columns that I need to include in this averaging but don't know how I can add that in. Any help is much appreciated.

Aucun commentaire:

Enregistrer un commentaire