MATLAB: Is this so slow

MATLABspeedup

Hi, All — the seemingly simple script shown below is exceedingly slow. It takes several minutes on a fast workstation. I can't figure out why it takes so long. What am I missing? Thanks, in advance.
N = 10^6;
a = 0;
b = 4;
r = a + (b-a)*rand(N,1);
c = r.*sinh(r);
k = (1:N)';
s(N,1) = 0;
for j = 1:N
s(j,1) = sum(c(1:j));
end
s = (b-a)*s./k;

Best Answer

Instead of loop why not simply use cumsum() ?