Changing Values in a column due to another value
    2 次查看(过去 30 天)
  
       显示 更早的评论
    
I have a collumn which contains 0s and 1s. The value 1 indicates that a failure occurred. I want to change the previous 6 rows prior to the failure to 1s also. 
Does anyone have any idea about the best method to do this? 
0 个评论
回答(1 个)
  Dyuman Joshi
      
      
 2021-5-30
        i = find(c==1,1,'first');       %c is the column vector
if i>6
    c(i-6:i-1)=1;
else 
    c(1:i-1)=1;
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!