MATLAB: Substitution of values of a matrix with values in a vector

substitution

if i have a matrix a=[0 0 0 0;0 0 2 0;0 1 3 4] and a vector b=[4;4;5;6], i want to substitution all values in the matrix a with the values of the vector b based on its order.
i want matrix a to be a=[0 0 0 0;0 0 4 0; 0 4 5 6]
is there a code to do it at once because i don't want to use a for loop

Best Answer

mask = a ~= 0;
a(mask) = b(a(mask));