0

i want to replace the element of array BW with element of array 'a' when element of BW is zero. Here is the code i have written

for i=0:row for j=0:col
if BW(i,j)==0 BW(i,j)=a(i,j); end
end end

i get error for if BW(i,j)=0

2 Answers 2

1

The easy way is:

BW(find(BW == 0)) = a(i,j)
Sign up to request clarification or add additional context in comments.

Comments

0

No need for the loop.

Index the zero elements in BW then replace with corresponding element in a

idx = BW == 0;
BW(idx) = a(idx);

This solution assumes that a is at least as big as BW

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.