Reputation: 48946
I have the function listed at the bottom of this post which is supposed to return a matrix that has the same size of a matrix x
with pixels that had a degree of membership y
=1 to 1
and the other pixels to 0
.
But, when I ran the function I didn't get the expected results as follows (why is that?):
>> x = [1 4 3; 6 4 3; 6 9 3; 2 4 3; 5 4 0; 5 3 1; 6 4 7];
>> y = [0 0 1; 1 1 0; 1 1 0; 0 1 1; 0.2 0.8 0.54; 1 1 1; 0 0 0];
>> pixel_val(x,y)
ans =
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
0 0 0
function c = pixel_val(x, y)
[ii,jj]=find(y==1);
x(ii,jj)=1;
[ii2,jj2] = find (y~=1);
x(ii2,jj2)=0;
c = x;
end
Thanks.
Upvotes: 0
Views: 38
Reputation: 2028
The indices [ii, jj]
returned by find
are not what you think they are.
You actually dont need two output arguments. Try this instead
ii = find(y==1);
x(ii) = 1;
ii = find(y~=1);
x(ii) = 0;
Or, better yet, use logical indexing rather than find
and do it in one line:
x(y==1) = 1;
x(y~=1) = 0;
Upvotes: 1