MATLAB: Loop and plot in 2D

2dfor loopplot

Hi,
I have a variable V(a,b,c) where
a=1:50
b=a
c=1:100
Now I would like to make a loop and plot the following:
sum_a(V(a,a+r,:))
May I ask you to help me with this loop and the 2D plot?
I have tried with this:
M=50;
V_prev=zeros(a,b,c);
V=V_prev;
for ik=1:M
V(ik,:,:)=V+V(ik,:,:);
for r=50-1:-1:0
V(ik,ik+r,:)=sum(V(ik,ik+r,:));
end
end
Unfortunately it doesn't work.
Thanks in advance for your reply.

Best Answer

l is a terrible name for a variable. Anyway, you need to make sure a+l is not more than M
if (a+l) > M
break;
end
V(a,l,:)=sum(V(a,a+l,:));