Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- How do I extract elements that are less than 0 or ...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-30-2016
07:54 AM

03-30-2016
07:54 AM

How do I extract elements that are less than 0 or bigger than 0 in a vector?

Hi Everyone,

I'm new here, so i dont know if i written this question under the right subjekt. I will start with saying that I'm sorry for my bad english.

Now to my question:

I'm sitting right now with a projet where i'll try to make a template to calculate some buildning structures. When i Do a bending moment controll i get an array (a vector) which has negative values and positive values in it. How do i in simple way extracting those elemetns which is less than 0 in a own array?

Like if i have a Vector A: [0

10

-5

-3

6]

And i want to extract just the negative values and end up with a vector like this:

[-5

-3]

How do I do?

I have searching in this forum but I haven't found a solution yet.

4 REPLIES 4

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-30-2016
09:04 AM

03-30-2016
09:04 AM

Re: How do I extract elements that are less than 0 or bigger than 0 in a vector?

You have to sort through the vector element by element. This is best done in a program; unfortunately Prime Express doesn't support programming (and a lot of other useful things.)

Which version of Mathcad are you using?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-30-2016
09:35 AM

03-30-2016
09:35 AM

Re: How do I extract elements that are less than 0 or bigger than 0 in a vector?

You could use a combination of "match" and "trim" to do the job

But this line will fail if no negative values are present

so we will use "onerror" (in Prime you would use "try") to catch that error and return the vector unchanged

But there is still a situation, where we will get unwanted results. If ALL values in the vector are negative, nothing will be left. This throws an error and because errors are trapped by "onerror" now we get back the original vector, which is not the desired behavior.

So I thought that now its time to write an utility function to do the job and call later when needed (I have chosen to return NaN in the last case, change as appropriate)

Hope this helps

Werner

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-30-2016
09:46 AM

03-30-2016
09:46 AM

Re: How do I extract elements that are less than 0 or bigger than 0 in a vector?

For completeness sake here the Prime version

The basic line (first one in my answer above) will work in Prime Express, too, but for the error catching you need the full version because "try" is a programming command and programming is considered a premium feature which is not enabled in the free Express variant.

EDIT: Just found that the "trim" command is also considered a premium feature, so not even the basic line won't work in Express

And just for fun here is an alternative, classic approach, going through the vector element by element and collecting the appropriate elements for the new, trimmed vector

WE

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-30-2016
12:29 PM

03-30-2016
12:29 PM

Re: How do I extract elements that are less than 0 or bigger than 0 in a vector?

Thank you for your answers!

I will look in to it! My university has MathCAD prime ver 3.1 on the computers in the computer lab. So this will absolutly help.

Best regards