Latency handling at filter output
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