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
- :
- program to compare 2 matrices

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

05-23-2020
08:23 PM

05-23-2020
08:23 PM

Hi,

I need to write a program to compare two matrices and eliminate non-identical rows. For example, please see attachment. In this case Matrix B can only contain numbers found in Matrix A. I need to compare each value of A with B and output values of B that matches with A (in the same order). Problem is some of the numbers in A do not appear in B and therefore, I am not able to use the match function. I would greatly appreciate any help.

Thanks.

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

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

05-24-2020
09:48 AM

05-24-2020
09:48 AM

Hi,

I take it back, The data presented in the first set of data on 24/03/2020 is different in B. On 24/03/2020 all values of A exist in B so my use of the match command works.

The second data set on 24/05/2020 only some values of A exist in B. So before use of the match command each time you need to check A is in B.

You can use match safely with any number in "otherresult"

Regards

Terry

7 REPLIES 7

Highlighted
##

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

05-24-2020
12:50 AM

05-24-2020
12:50 AM

Re: program to compare 2 matrices

Hi,

This exact question (including the values) has been asked before.

Here is the solution given then.

Cheers

Terry

Highlighted
##

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

05-24-2020
04:27 AM

05-24-2020
04:27 AM

Re: program to compare 2 matrices

It looks to me that your solution is for a different problem and a different excel sheet. There is not data in the area "F3:G60" in the sheet provided by the OP.

Highlighted
##

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

05-24-2020
04:43 AM

05-24-2020
04:43 AM

Re: program to compare 2 matrices

Hi,

This post is a subset of data in a question posted earlier. In the earlier post the data in area B2:B18 is a calibration factor. In the earlier post data in area G3:G60 is an experimental result. The problem is to use the right calibration factor from B3:B18 on the data in G3:G60 depending on the matching numbers in A3:A18 and F3:F60.

It is clearly a homework question where the second submitter has reduced the data set.

I enclose the first submitter's dataset.and the full answer to the homework in question.

Highlighted
##

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

05-24-2020
07:42 AM

05-24-2020
07:42 AM

Re: program to compare 2 matrices

Hi Terry,

Thanks for the reply. This is not working because, for imatch, it is telling me no matching values found. That is why I said in my initial post that the match function does not seem to be working in this case and I am not sure why. Kindly check attachment.

Regards

Highlighted
##

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

05-24-2020
04:25 AM

05-24-2020
04:25 AM

Re: program to compare 2 matrices

You could create a custom "match" function which returns whatever value (maybe NaN or 0) you want in case the built.in "match" command fails.

I am irritated by you writing "in the same order". Does this mean that 60016 would be not in the result list because it appears in A BEFORE 60029 but in B just after 60029 ?

What exact result do you expect using your test data and why do you post an excel sheet and not a simple Mathcad sheet with the two matrices already included? Would be easier to deal with.

Highlighted
##

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

05-24-2020
09:04 AM

05-24-2020
09:04 AM

Re: program to compare 2 matrices

The attached worksheet does what you ask (per your description): It checks all values in B, compares them with values in A and outputs only those values of B that are also in A, in the order in which they appear in B.

Given your data, it is now (also) checked that ALL values in B do in fact occur in A.

Is this what you want?

For clarity, if I add 2 to all values of B, some of those sums will not be in A, the result is a smaller list:

Success!

Luc

Highlighted

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

05-24-2020
09:48 AM

05-24-2020
09:48 AM

Hi,

I take it back, The data presented in the first set of data on 24/03/2020 is different in B. On 24/03/2020 all values of A exist in B so my use of the match command works.

The second data set on 24/05/2020 only some values of A exist in B. So before use of the match command each time you need to check A is in B.

You can use match safely with any number in "otherresult"

Regards

Terry