×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

How do I count non-zero entries in a vetor matrix

How do I count non-zero entries in a vetor matrix

How do I count non-zero entries in a vetor matrix

(OP)
I have a vector matrix with 20 entries.  If I use the length(x)= ## comand it counts out the number of possible entires in my vector but I need it to only count the non-zero entries. I'm not very good with mathcad so does anyone have any suggestions?

I've attached and example of what I have but someone before me wrote it so I don't understand how it works or what it's doing so therefore I can't duplicate it for a different vector were some of the entries are negative.

RE: How do I count non-zero entries in a vetor matrix

You need to count them by inspection, i.e., build a subroutine that examines every number in the vector and adds to a counter that first is initialized to zero if and only if the current number is other than zero, then once examined all numbers produce the final status of the counter as output. Ensure that your tolerance identifies well what for you is a zero, otherwise you'll get wrong values by your criteria.

RE: How do I count non-zero entries in a vetor matrix

frogger79,
just re-read what you were looking for; i.e. non-zeros...  

To do this you need to change the 'n' in the (n vn) term within the loop to 'length(Space)-n' and then you'll have the number of non-zero terms in your data set.

Uploading MathCad died for some reason, hence the long-hand version shown in above paragraph...sorry!

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!


Resources