cycle over matrix