update matrix