Skip to main content
1-Visitor
February 15, 2023
Solved

How to find the name of a variable in a set of data

  • February 15, 2023
  • 2 replies
  • 1542 views

How do I find the name of the variable that has the maximum value in a set of data. For example, if I have x=3, y=5 and z=2. I want to find the variable name for the maximum value. In this case it would be "y".

 

 

Best answer by Werner_E

Unfortunately Prime offers no way to access the NAMES of variables.

But if you collect all values in a vector, you cannot only find the maximum value but also the positions, the indices where in the vector this value occurs. Notice that by default the first element has the index 0.

Werner_E_0-1676491859617.png

 

2 replies

Werner_E25-Diamond IAnswer
25-Diamond I
February 15, 2023

Unfortunately Prime offers no way to access the NAMES of variables.

But if you collect all values in a vector, you cannot only find the maximum value but also the positions, the indices where in the vector this value occurs. Notice that by default the first element has the index 0.

Werner_E_0-1676491859617.png

 

1-Visitor
February 15, 2023

Thank you for your response! I was able to take what you said one step further. I am not worried about repeating numbers. I am just trying show the maximum moment on a beam with different load cases. 

 

SD_8739877_0-1676504897705.png

 

25-Diamond I
February 16, 2023

You could also use the lookup() function to do the job.

But nonetheless it is still necessary to define a separate vector with the "names".

Werner_E_0-1676522107844.png

 

15-Moonstone
February 15, 2023

This question does not appear to be well formulated. One reason that many of us use Mathcad is that it is "unit aware", How should it compare variables with different SI types unless, as Werner hints, you first collect all your variables into groups of common types and the look for the maximum of each type.

 

But then, how do you compare these maximums?