MATLAB: Conditional adding of elements to an array

array conditional quotient remainder

i have the following array: [2 2 4 6 7 16 20 29 48 81 130 163 235 308 414 496 535 521 509 465 355 275 198 120 72 31 16 8 4 2]
what i want to do is if the element of the array is greater than 50, then i replace the element by the the 50 then by the remainder so for example after converting the 10th element the array becomes [2 2 4 6 7 16 20 29 48 50 31 130 163 235 308 414 496 535 521 509 465 355 275 198 120 72 31 16 8 4 2]
how wcan this be done for any array ?

Best Answer

A = your data vector
n = whatever (e.g., 50)
result = cell2mat(arrayfun(@(x)[repmat(n,1,floor(x/n)),rem(x,n)],A,'uni',false));