Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

One function returns the correct results, the opposite not. Why?

Status
Not open for further replies.

AbderRahman

Computer
Jun 18, 2008
2


I have the following function that checks the pixels from `x` that have the membership value `near 1` and sets those pixels in `x` to `1` and return them back. The works pretty well for me:

function c = core(x, y)
tolerance = 0.01;
[ii,jj]=find (abs(y)-1 <= tolerance);
x(ii,jj)=1; % set pixels in x with y=1 to 1
idx=[ii,jj]; % indexes of pixels with y=1
c=x(abs(y)-1 <= tolerance); % values of pixels
end

Now, to the opposite function below. I just want to check the pixels that have membership values values `not equal to one` and since in my case I don't have exactly value `1` and this used `tolerance`. I wrote what I think is the opposite of the above, but my output is an `empty matrix`. Why is that? What should I change in the function below?

function s = support(x, y)
tolerance = 0.01;
[ii,jj]= find (abs(y)-1 > tolerance);
x(ii,jj)=0; % set pixels in x with y~=1 to 0
idx=[ii,jj]; % indexes of pixels with y~=1
s=x(abs(y)-1 > tolerance); % values of pixels
end

Thanks.
 
Replies continue below

Recommended for you

Brackets look fine to me. Code also works fine for me:

Code:
>> x = [1 2 3 4 5 6];
>> y = [1.001 1.5 1.005 4 0.995 0.999];
>> core(x, y)

ans =

     1     1     1     1

>> support(x, y)

ans =

     0     0

Not sure why you'd want to do this, but the two functions certainly perform opposite functions and neither returns an empty matrix (unless of course, no values satisfy the condition).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor