Latency handling at filter output In MATLAB, latency at the start of the output of a filter can be handled by discarding those bits and starting the signal where the latency ends. but how can the garbage value at the end be handled?
You may use the internal state variable zf that is available as an output from the filter function

[y,zf]=filter([ 1 2 3],1,[1 0 0 0 1 ])


it contains the final condition of the filter, in the example above (with b=[1 2 3] and a=1) you will get

y =

     1     2     3     0     1

zf =

     2
     3


Concatenating zf to the end of y will give you the complete output signal, it is the same as adding zeros to the input signal at the end.

 y=filter([ 1 2 3],1,[1 0 0 0 1 0 0])

 y =
     1     2     3     0     1     2     3