accumarray
各グループの最後以外のすべての観測を削除する方法はありますか?
私が念頭に置いていたのは、似たようなものでした:
lastobs=accumarray(bin,x,[],@(x){pick the observation with the max index in each group};
例を挙げると、次のようなものがあるとします。
bin=[1 2 3 3 3 4 4]; %#The bin where the observations should be put
x= [21 3 12 5 6 8 31]; %#The vector of observations
%#The output I would like is as follow
lastobs=[21 3 6 31];
私が実際に考えているのはaccumarray
、それを使用して各ビンの観測値の平均を計算したからです。したがって、トリックを作成できるすべての機能は、私にとっては問題ありません。