Best illustrated by example
M=rand(5,10);s=[1 3; 5 8; 9 10];for i=1:size(s,1)sm(:,i)=sum(M(:,s(i,1):s(i,2)),2);end
Is there a one-liner or short-cut for the for loop? I do not know how large M or s is ahead of time, or their values. Above code shown only for illustration of problem trying to solve.
Thanks!
edit: Corrected typo of 'm' in for-loop to 'M'
Best Answer