MATLAB: For-Loop Midpoint Help

for loop

I'm looking to make a for-loop that looks 50 indices ahead and 50 indices behind, but the code won't precede past the line: elseif sum(count(max(i-49,1)):i,length(count)) > 1, I think it has something to do with the max function, but can't seem to work around it. Any help would be appreciated. Count is already defined as a vector of zeros or ones previously in the script.
for i = 1:length(count);
if sum(count(i:min(i+49,length(count)))) > 1
count(i) = 50;
elseif sum(count(max(i-49,1)):i,length(count)) > 1
count(i) = 50;
else
count(i) = 0;
end
end

Best Answer

since you want it to do both +50 and -50 you can't have the if/else structured that way. you'll have to do break it up. if you read about the if/elseif, it won't go into the elseif section if the first if is true
The statements after the elseif are executed if the expression is true and all the preceding IF and elseif expressions are false
taken from the help elseif documentation.
also looking at the count as you're modifying it wouldn't after your first count(i)=50 always cause it to be 50 from then on?