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
- :
- What does the match function do?

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

09-03-2014
11:18 AM

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

09-03-2014
11:18 AM

What does the match function do?

Hi

I use the match function to find a value in a vector. However, for some values the match function returns a matrix instead of a scalar, see picture. Why does this happen? What is the match function doing?

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

09-03-2014
12:09 PM

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

09-03-2014
12:09 PM

Your TOL value is set at the default of 1e-3, so there is no difference between 0.005 and 0.006. Therefore, 'match' returns two values, 2 and 3. If you change TOL to 1e-4 (e.g.), you will get the results that you want. Note, however, that 'match' ALWAYS returns an array, even if it is one element -- if you want the scalar, you're going to need to subscript that sucker.

4 REPLIES 4

09-03-2014
11:47 AM

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

09-03-2014
12:09 PM

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

09-03-2014
12:09 PM

09-03-2014
07:49 PM

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

09-03-2014
07:49 PM

As Moe already wrote, the reason is the value of the system variable TOL.

You can use the match function with a third argument (in MC 15 you will have to write a capital M in Match).

The third argument may be a boolean function and you can chose a better equality that way (see the screenshot, I have chosen an inline definition of the function to keep it al in one region.

The third argument can also be one of a set of special strings. According to the help "eq" should do what you expected but it seems that "eq" and "near" are doing the same - they are dependent on the setting of TOL. We may call this a bug!? Either in the implementation or the documentation.

In Mathcad 15 we have the same effect. Here "eq" is not mentioned in the help documentation at all but is already accepted by Match (obviously as an alias of "near").

09-04-2014
02:18 AM

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

09-04-2014
02:18 AM

Thanks a lot guys