Actually I manage to figure it out.
Here is solution, thought may be helpful for some others.
% idx is an array having index numbers
Result = zeros(length(idx),1); % define size of result
for i= 1:length(idx)
data = EnergyB((idx(i,1)):idx(i,2));
Result(k) = sum(data/3.6/1000000) % use 3.6/1000000 for converting joules to kWh