variance check in matlab algorithm