function c=toggle(a,x)
	if(rem(x,3)==0)
		b=[x-3 x-1 x x+3];
	elseif(rem(x,3)==1)
		b=[x-3 x x+1 x+3];		# vector b stores the switch numbers which will be toggled by pressing the switch x;
	else
		b=[x-3 x-1 x x+1 x+3];
	endif
	for i=1:length(b)
		if(b(i)>0 && b(i)<10)
			a(b(i))=1-a(b(i)); 	# toggles the value of switch
		endif
	endfor
	c=a;		# returns matrix c which is the state of matrix a after pressing switch x;
endfunction