MATLAB: How to replace values

replacing values

How can I replace values? I've a matrix of 3653×337 Let's consider I've
  • dates values
  • 0101 0
  • 0102 0
  • 0103 0
  • 0104 1
  • 0105 0
  • 0106 0
  • 0107 0 ….
I need a function to find all these "1"'s in my matrix and to replace it for two days before and after I've a "1".
Thanks!

Best Answer

Here is a simple way that should be easy to understand. I am sure there are slicker ways, but maybe this will suit your purpose.
oldIndex = find(values==1);
newIndex = unique([oldIndex-2; oldIndex-1; oldIndex; oldIndex+1; oldIndex+2]);
values(newIndex) = 1;