Funtion for switch matrix