Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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


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

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


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

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

CODE --> Matlab

>> 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).

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close