Home > utility > replaceZeroWithPrevOne.m

replaceZeroWithPrevOne

PURPOSE ^

replaceZeroWithPrevOne: Replace zero with previous non-zero element

SYNOPSIS ^

function out=replaceZeroWithPrevOne(in);

DESCRIPTION ^

 replaceZeroWithPrevOne: Replace zero with previous non-zero element

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Tue 01-Jun-2010 09:50:34 by m2html © 2003