So I am currently using \'accumarray\' to find the averages of a range of numbers wich correspond to matching ID\'s. Ex Input:
ID----Value
1 215
1 33
@Naveh - Generally, it is advised to avoid using loops in Matlab. Specifically, if you have a large set of data with many groups - it can be very slow.
Using accumarrayis the way to go, but defining a function of the indices, as suggested by @chappjc, is error-prone, since in order to be be captured by the anonymous function, you must make sure that
data is not an input to WeightedMeanFcn. It must be defined before defining WeightedMeanFcn,
as @chappjc says in his comment.
A slight modification to overcome this problem is to use accumarray twice:
Weights = data(:,3); Vals = data(:,2); % pick your columns here
app = accumarray(Groups, Weights.*vals, [], @mean)./accumarray(Groups, Weights, [], @mean);
Sometimes you may need to replace the [] argument by the size of the required output.