We demonstrated an optical coding method to measure the position of each particle in a microfluidic channel. The technique utilizes a specially designed pattern as a spatial mask to encode the forward scattering signal of each particle. From the waveform of the forward scattering signal, one can obtain the information about the particle position and velocity. The technique enables us to experimentally investigate the complex relations between particle positions within the microfluidic channel and flow conditions and particle sizes. The method also produces insight for important phenomenon in microfluidic and lab-on-a-chip devices such as inertial focusing, Dean flow, flow confinement, etc.