I have a large matrix and need to loop through it and find where there are instances of 4 or more 0's and replace these 0's with 2's. For example, in the below image I need to replace the 4 or more consecutive 0's (red) with 2's but the other 0 further down is fine. The image on the right is what I'm expecting.
I can count the number of times 0 appears but am stuck on how to alter these 0's. This is what I have so far:
for i = 1:length(x) y = x(:,end); if y(i) == 0 count = count + 1; else if count >= 4 lastIndex = i - 1; %change 0's in the block of 4 to 2's
%this is the bit I'm stuck on
count = 0; %reset count
end count = 0; endend
Any help would be greatly appreciated.
Best Answer