cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Translate the entire conversation x

match and lookup functions

YA_10963798
14-Alexandrite

match and lookup functions

Hi there 

What is the difference between ( match) and ( lookup ) function in mathcad prime 11

thanks 

Yusra 

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald IV
(To:YA_10963798)

Match gives the location(s) (index/indices) of the element(s) found, while lookup gives the value(s) of all/an element(s) in (a) location(s) that correspond(s) to the element(s) found.

With matrix:

LucMeekes_0-1769441034898.png

LucMeekes_2-1769441058045.png

tells you that the 2 is found at row position 1 in colum 0.

LucMeekes_3-1769441095808.png

gives you the value in column 1 of that matrix, at the same row where 2 is found in the first column (column 0).

 

You can also get the value of the element found, by looking up in the same array as where you search...:

LucMeekes_4-1769441260658.png

but the usefullness of this may be questionable.

 

As Werner shows, you get multiple results, if the value you look for occurs multiple times in the array.

 

Success!

Luc

View solution in original post

8 REPLIES 8
LucMeekes
23-Emerald IV
(To:YA_10963798)

Match gives the location(s) (index/indices) of the element(s) found, while lookup gives the value(s) of all/an element(s) in (a) location(s) that correspond(s) to the element(s) found.

With matrix:

LucMeekes_0-1769441034898.png

LucMeekes_2-1769441058045.png

tells you that the 2 is found at row position 1 in colum 0.

LucMeekes_3-1769441095808.png

gives you the value in column 1 of that matrix, at the same row where 2 is found in the first column (column 0).

 

You can also get the value of the element found, by looking up in the same array as where you search...:

LucMeekes_4-1769441260658.png

but the usefullness of this may be questionable.

 

As Werner shows, you get multiple results, if the value you look for occurs multiple times in the array.

 

Success!

Luc

YA_10963798
14-Alexandrite
(To:LucMeekes)

Thanks a lot 

Werner_E
25-Diamond I
(To:YA_10963798)

match(z,A) returns a vector of indices of the position(s) z is found in matrix A

lookup(z,A,B) returns a vector of values from matrix B from the position(s) z is found in A

 

See the Prime help here: Lookup Functions

 

Simple example:

Werner_E_0-1769441482857.png

 

EDIT; Oh, too late—Luc has beaten me by one minute. 🙂

 

 

 

 

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Hi Werner 

I'm trying to use this function, that you showed me before 

YA_10963798_0-1769589784913.png

to get q in the corresponding ztips depth

I wrote it like this 

YA_10963798_1-1769590237357.png

can you tell me what is wrong with this program 

Should I use match or change the iterator ? 

I attached the sheet 

Thanks

Yusra 

Werner_E
25-Diamond I
(To:YA_10963798)

From the picture I see that your program does some calculations but at the end it returns "q" unchanged and that's what you finally get. 😉

 

Could it be that you are looking for something like this:

Werner_E_2-1769596424183.png

 

The results are all NaN's because none of the values in ztips matches any  value in the vector ztop (which is then called z in the program).

I also suspect that you meant to use -z when you call the program and not ztop (qused := qs;d(q.-z,ztips). But this does not change the NaN's because none of the values in ztips matches any value in -z as well.
At least i guess that the second argument when calling qs;d should be a 2312x1 vector like the three vectors in q and not a 11x1 vector like ztop .

Werner_E_1-1769596371153.png

 

I can't remember what the question was when I provided the function you refer to and what the data was at that time.and I don't know what you intend to calculate now. Maybe you need to use a modifier like "geq", "lt", "near", etc. (see the help), but I can't possibly know.

 

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Thanks for the explanation 

Werner_E
25-Diamond I
(To:YA_10963798)

It looks to me that in last time you often try to rewrite a function which used a single vector q as its argument to work for a nested matrix q.

Instead of modifying the function which already worked OK for a single vector, I would suggest writing a new function for the nested q which simply calls the existing and working function multiple times for every element in q, collects the results and returns them as nested matrix.

In your case this would look like this:

Werner_E_0-1769601926955.png

You may also make a function which can be used for single and for nested inputs equally well:

Werner_E_1-1769602039833.png

Of course all of this does not change the NaN's which are returned because there are no exact matching values.

YA_10963798
14-Alexandrite
(To:Werner_E)

Nice 

Always an amazing reply . I fixed the input and get the answers needed 

Thanks a lot 

Announcements

Top Tags