hi Bruno Luong thanks for the solution and your time. this solution works well with small example. the actuall size of dataset i am working on is big. it has 1049866 rows in array A. and when i applied your solution to that dataset it gives me following error massege:
??? Error using ==> accumarray Maximum variable size allowed by the program is exceeded.