Can I do this summation without the for loops?

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

 Accepted 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.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 15 Jan 2014

Commented:

on 15 Jan 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!