


replaceZeroWithPrevOne: Replace zero with previous non-zero element


0001 function out=replaceZeroWithPrevOne(in); 0002 % replaceZeroWithPrevOne: Replace zero with previous non-zero element 0003 0004 % Roger Jang, 20051004 0005 0006 if in(1)==0 0007 error('The first element should not be zero!'); 0008 end 0009 0010 out=in; 0011 for i=2:length(out) 0012 if out(i)==0 0013 out(i)=out(i-1); 0014 end 0015 end