Skip to main content
14-Alexandrite
September 21, 2023
Solved

Lookup value

  • September 21, 2023
  • 1 reply
  • 1358 views

Hello,

 

In Mathcad prime, when a value is looked up from an Excel sheet, the output will be placed in a square bracket , I assume it is an array. When I use the looked it up value and compare it with another value, it gives an error saying it must be a scalar. What do I need to do to the looked up value to make it a scalar?

 

Thanks,

Sam

 

 

 

Best answer by Werner_E

Lookup will always return an array because its quite possible that more than one value fulfills the condition given. So you also get a 1x1 array if just one single entry applies.

You may choose the very first entry in the list by adding the matrix index 0 (assuming that ORIGIN=0)

Werner_E_0-1695325229410.png

 

You may also consider to use a user-written lookup function, placed somewhere at the top of the sheet (maybe in a collapsed region) which does that job:

Werner_E_0-1695325635232.png

Thanks to the try,,,on error it will not throw an error if no match was found but returns a NaN (or change to whatever you feel appropriate).

Unfortunately user functions can't have an optional argument. So if you need the lookup function with the optional fourth argument you would have to use a second user function

Werner_E_1-1695325770373.png

 

 

1 reply

Werner_E25-Diamond IAnswer
25-Diamond I
September 21, 2023

Lookup will always return an array because its quite possible that more than one value fulfills the condition given. So you also get a 1x1 array if just one single entry applies.

You may choose the very first entry in the list by adding the matrix index 0 (assuming that ORIGIN=0)

Werner_E_0-1695325229410.png

 

You may also consider to use a user-written lookup function, placed somewhere at the top of the sheet (maybe in a collapsed region) which does that job:

Werner_E_0-1695325635232.png

Thanks to the try,,,on error it will not throw an error if no match was found but returns a NaN (or change to whatever you feel appropriate).

Unfortunately user functions can't have an optional argument. So if you need the lookup function with the optional fourth argument you would have to use a second user function

Werner_E_1-1695325770373.png

 

 

SFares14-AlexandriteAuthor
14-Alexandrite
September 21, 2023

Thank you Werner!