I have one matrix data like that:
1 2 3
1: 1.0 2.0 5.0
2: 2.0 2.0 5.0
3: 4.0 0 5.0
And another matrix test like this:
1 2 3
1: 3.0 0 0
2: 0 5.0 0
3: 0 0 3.0
The problem: set data so that: data(i,j) = 0 when test(i,j) == 0
My code for that:
for i=1:N
for j=1:M
if test(i,j) == 0
data(i,j) = 0;
end
end
end
Question: Is there a loop-free way to do this/
Yes. Try this
or as @Peter says in comment below, this simpler form will suffice