Why am I not getting the expected result?
1 view (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Azzi Abdelmalek
on 23 Feb 2013
Edited: Azzi Abdelmalek
on 23 Feb 2013
You don't need to create a function for this
x=zeros(size(y))
x(y==1)=1
and x is not used in your code
0 Comments
More Answers (1)
Walter Roberson
on 23 Feb 2013
It was explained for you already. Read http://www.mathworks.co.uk/matlabcentral/answers/64472-one-function-returns-the-correct-results-the-opposite-not-why#answer_76075
0 Comments
See Also
Categories
Find more on Import, Export, and Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!