Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. colvec TestProcessing::accumarray(icolvec cf, colvec T, double nf, int p)
  2. {
  3. /* ******* Description *******
  4.  
  5. here cf is the matrix of indices
  6.  
  7. T is the values whose data is to be
  8. accumulted in the output array S.
  9.  
  10. if T is not given (or is scaler)then accumarray simply converts
  11. to calculation of histogram of the input data
  12.  
  13. nf is the the size of output Array
  14.  
  15. nf >= max(cf)
  16. so pass the argument accordingly
  17.  
  18. p is not used in the function
  19.  
  20. ********************************/
  21.  
  22. colvec S; // output Array
  23.  
  24. S.set_size(int(nf)); // preallocate the output array
  25.  
  26. for(int i = 0 ; i < (int)nf ; i++)
  27. {
  28. // find the indices in cf corresponding to 1 to nf
  29. // and store in unsigned integer array q1
  30. uvec q1 = find(cf == (i+1));
  31. vec q ;
  32. double sum1 = 0 ;
  33.  
  34. if(!q1.is_empty())
  35. {
  36. q = T.elem(q1) ; // find the elements in T having indices in q1
  37. // make sure q1 is not empty
  38.  
  39. sum1 = arma::sum(q); // calculate the sum and store in output array
  40. S(i) = sum1;
  41. }
  42.  
  43. // if q1 is empty array just put 0 at that particular location
  44. else
  45. {
  46. S(i) = 0 ;
  47. }
  48. }
  49. return S;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement