MATLAB: How to vectorize operations on arrays which involve the colon ‘:’ for indexing purposes

MATLAB

The goal is to vectorize a for-loop containing vector operations involving the colon ':' for indexing purposes. The loop has the following form,
 
>> arr = rand(1, 100);
>> num = 10;
>> const = 5;
>>
>> for i = 1:num
>> arr_vct(i) = sum(arr((2 + (i - 1)*const):(1 + const*i)));
>> end

Best Answer

The solution in this case involves the use of the 'reshape' operator and the latter for-loop can be compactly written in the following single line of code,
 
>> num = 10;
>> const = 5;
>> arr_vct = sum(reshape(arr(2:(1 + num*const)), const, []));