MATLAB: How to make a matrix mirror another

array

How do I do this?
X=[4 7 1 0;
3 0 6 8]
Y=[32 6 4 21;
77 89 0 2]
X(X==0)=a;
after the alteration:
X=[4 7 1 a;
3 a 6 8]
Y=[ 32 6 4 a;
77 a 0 2];

Best Answer

Try this:
a = 42;
X=[4 7 1 0;
3 0 6 8]
Y=[32 6 4 21;
77 89 0 2]
Idx = X==0
X(Idx) = a
Y(Idx) = a % Use The Same Index On Both Matrices,