samer@54: function H=accumhist(I,W,D) samer@54: % accumhist - Just like accumarray but filters out rows with nans or infs samer@54: % samer@54: % accumhist :: samer@54: % [[N,E]->(natural|nan|inf|-inf)] ~'N rows of E-dim array indices', samer@54: % ([[N]->real] | real) ~'the weights associated with each row', samer@54: % D:[[E]->natural] ~'the size of the array to return' samer@54: % -> [[D]]. samer@54: % samer@54: % Note that unlike with accumarray and other Matlab builtins, the size samer@54: % argument D can be a single element, eg [M], indicating that a vector samer@54: % is desired. accumarry would require [M 1]. samer@54: samer@55: K=all(isfinite(I),2); samer@56: if ~isscalar(W), W=W(K); end samer@56: H = accumarray(I(K,:),W,tosize(D)); samer@54: