MATLAB: Help with for loop – How to use indices to denote intervals

for loopsmatrix manipulation

I have a vector A, for example (1:1:600)'.
I have a matrix B with indices denoting which rows of A that I want to perform a calculation on. These indices are in intervals – B(:,1) is the start and B(:,2) is the end of each interval – for example B(:,1)=[5,15,25,35,45] and B(:,2)=[10,20,30,40,50] (corresponding to intervals 5-10,15-20,25-30,35-40,45-50).
I want to use the intervals specified in B to change something about A. This needs to happen for various reasons in my data, but for simplicity let's say I want to change values in the rows corresponding to those intervals to zero. I have been trying to use a for loop but I am missing something.
I have: for i=B(:,1); for j=B(:,2); A(i:j,:)=0; end; end;
Now, I would hope that this would change the values of rows 5-10,15-10,25-30,35-40,45-50 to 0, but the command is only executed for the first interval (rows 5-10), not the rest.
I am pretty new to Matlab and so I am sure I am missing some subtle and easy thing here. I have tried searching through all of the help topics and other people's questions but I can't find anyone else trying to use the indices as intervals.

Best Answer

Edit
n=size(B,1);
for k=1:n;
ii=B(k,1)
jj=B(k,2)
A(ii:jj,:)=0;
end