I have a matrix that has 3 columns that consist of -1, 0, and 1 (let's call them the "level columns"), and a fourth column that contains real numbers (call it the "data column"). For the level columns, I want to find the average of the "-1", "0", and "1" terms in the data column. So for the following matrix,
-1 -1 0 837 -1 0 -1 880 -1 0 1 879 -1 1 0 864 0 -1 -1 834 0 -1 1 833 0 0 0 874 0 0 0 875 0 0 0 876 0 1 -1 860 0 1 1 859 1 -1 0 829 1 0 -1 872 1 0 1 874 1 1 0 856
the -1 average for column 1 would be 865. Is there a way that I can do that all at once, for each level column, and each level column value? Right now, I loop over the level columns and do this:
[mean(testMat(testMat(:,col) == -1,4)) mean(testMat(testMat(:,col) == 0,4)) mean(testMat(testMat(:,col) == 1,4))]
Is there a better way?
Thanks!
Best Answer