Is there a nice, simple script one can use to swap two entires in a matrix? For example, suppose we have the matrix below:
$A=\begin{pmatrix}2 & 4 & 1\\ 3 & 1 & 2\\ 4 & 3 & 1 \end{pmatrix}$
Is there a script of the form switch[A,a,b], which will swap all occurrences of $a$ in the matrix with $b$, and vice versa, and then update the matrix $A$ accordingly? So in this case the output of switch[A,2,3] would be:
$A=\begin{pmatrix}3 & 4 & 1\\ 2 & 1 & 3\\ 4 & 2 & 1 \end{pmatrix}$
My own solution involves a lot of If and For functions, and will, I think, also run into the problems detailed here. I think it will work eventually (and I'd be happy to post what I have so far if people would like), but really I'm just wondering whether there's a simpler way to do this.
Thanks!

Dispatch[Apply[Join, Thread[# -> Reverse[#]] & /@ pairs]]. – J. M.'s missing motivation Aug 26 '12 at 11:21swapfunction do not replace the original matrix itself? (I mean, if bothaand swappedaare needed.) – Noble P. Abraham Aug 26 '12 at 13:24swapas a general function, it might be better if it does not replace. – Noble P. Abraham Aug 26 '12 at 13:42mat=in the definition ofswapand usea=swap[a,...]when one needs to replacea. – kglr Aug 26 '12 at 13:53