Iterate over matrix directly