add mid and post function in matrix