Q:

Replace missing value in an array

I have an array A=[3 4 1 2 5 6] and another array B=[3 4 0 2 0 0]
I tried to find out the missing elements of B using setdiff function of Matlab.
missing_values=setdiff(A,B);

i got answer as
missing_values= 1 5 6

Now i want to replace zeros of array B with missing values....
can you help me?
i tried the code given below:
j=1;
missingvalues=setdiff(A,B)
idx= nwP4(2,: )== 0;
if(A(idx)==0)    
A(idx) = missingvalues(j);
j=j+1;    `enter code here`
end 

but it didn't work. 
can you help me?

A:

Try this. I assume this is what you are trying to do.
A=[3 4 1 2 5 6]
B=[3 4 0 2 0 0]

missing_values=setdiff(A,B);
B(find(~B))=missing_values

Or to do it in one line, 
B(find(~B))=setdiff(A,B);

This will leave B with 
B = [3   4   1   2   5   6]

