Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- colvec TestProcessing::accumarray(icolvec cf, colvec T, double nf, int p)
- {
- /* ******* Description *******
- here cf is the matrix of indices
- T is the values whose data is to be
- accumulted in the output array S.
- if T is not given (or is scaler)then accumarray simply converts
- to calculation of histogram of the input data
- nf is the the size of output Array
- nf >= max(cf)
- so pass the argument accordingly
- p is not used in the function
- ********************************/
- colvec S; // output Array
- S.set_size(int(nf)); // preallocate the output array
- for(int i = 0 ; i < (int)nf ; i++)
- {
- // find the indices in cf corresponding to 1 to nf
- // and store in unsigned integer array q1
- uvec q1 = find(cf == (i+1));
- vec q ;
- double sum1 = 0 ;
- if(!q1.is_empty())
- {
- q = T.elem(q1) ; // find the elements in T having indices in q1
- // make sure q1 is not empty
- sum1 = arma::sum(q); // calculate the sum and store in output array
- S(i) = sum1;
- }
- // if q1 is empty array just put 0 at that particular location
- else
- {
- S(i) = 0 ;
- }
- }
- return S;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement