MATLAB: Can I do this summation without the for loops

sumsummation

for i=1:33
for j=1:7
for l=1:25
Total_V(i,j,l)=0;
for k=1:6
Total_V(i,j,l)= Total_V(i,j,l)+Car_Stock(i,j,k,l);
end
end
end
end

Best Answer

The inner loop can be replaced by
Total_V(i,j,l) = sum(Car_Stock(i,j,:,l));
And from that you can proceed to
Total_V = squeeze(sum(Car_Stock,3));
as the entire set of loops.