Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Is there a way to lookup a value in a matrix based on more than one given value? For instance, I want to give a value to match in column 1 and another value to match in column 2 that returns a value from column 3.
Any ideas? I haven't been able to find this topic anywhere, but I can't be the first person to want to do this.
Thanks in advance.
I'm not exactly sure what you're trying to get at, do you have an MC spreadsheet for what you want to do?
The first idea that came to my mind was creating a program to scan the rows and colums of the matrix (simple i,j "for" loops) to find input values that you provide and then spit out the third value.
Thank you, Stephen.
The "for" loops may be the best solution. I was hoping there was a shorter way.
I have attached an example of what I am trying to do.
Alright thanks for the sheet, that helped.
I've come up with a solution for the rather small matrix you provided but my program might run into problems if the matrix was a little bit more complicated. In regards to the actual matrix you want to use this program on, does it follow the same form as the example (two size choices for each style)? If not, my solution may need some alterations. Hope this helped!
Here's an alternative to Stephen's approach that will find all matching rows, even if there is more than one of them. This is easily extensible to matching any number of criteria in different columns.
Hmm, that does seem to work better. I wasn't aware of the "match" function and the other lookup functions and that would have made it easier. = )
That is a good one, Richard.
Thanks to both of you for your help.
No problem. Thanks to Richard for indirectly showing me the match/lookup functions. Learn something new everyday!
Just thought I would chip in with my effort (If its right).
More examples = Quicker learning.
I think I have eliminated the use of the for loop.
Mike.
Your code assumes that when you match x and Matrix the result (ss) is a two element vector. What if it has three elements? Or five? Try changing the styles to 1,1,1,2, the sizes to 30,30,40,50, and then searching for style=1 and size =40.
Richard Jackson wrote:
Your code assumes that when you match x and Matrix the result (ss) is a two element vector. What if it has three elements? Or five? Try changing the styles to 1,1,1,2, the sizes to 30,30,40,50, and then searching for style=1 and size =40.
Yes agree Richard, my example is only applicable for the Matrix posted.
I'll have a look and try and adapt my effort.
Cheers
Mike
Richard,
I give up with my example - I'll just file your example and make notes.
I know the vector sum function is required, but could you confirm exactly why? - just so I can add a note to the saved worksheet.
Mike
I know the vector sum function is required, but could you confirm exactly why? - just so I can add a note to the saved worksheet.
It's easiest to explain that in a Mathcad worksheet. See the attached.
Richard,
Excellent explanation and cheers for taking time to explain the function.
I would recommend anybody who is unsure as I was, on how Richard got his function to work, to download his sheet and follow the steps.
Mike
Not so nicely closed out, Mike. The function must include the row extractor, otherwise on a longer matrix, you wouldn't have enough indication of the project. Think in term of a scatter plot for which you need to know the the row of the matched search ... for instance a spot check of a manufactured object.Either versions [modular or conclusive] can be plugged in the "Project Utilities". The"modular" is a good learning step, that can be compacted to the "conclusive". I will plug my new pest in a separate thread, you know what ? I have cleaned my stuff previous to your last message [and will continue this way of doing to keep this site clean on my side] ... guess what !!! My stuff was before yours, and deleting my stuff delete your post message to mine. That could mean disaster in the case the past poster had a work sheet. Hard to believe Dan's algorithm is so stupid.
Jean
Cheers Jean,
I like row extractor function, will definately be used in the future.
Mike
MIke Armstrong wrote:
Cheers Jean,
I like row extractor function, will definately be used in the future.
Mike
Mike, here is how the row extractor will work for you :
modular or programmed. A precious piece of utilities.
Jean
Jean,
Cheers for the function.
Have a look at the attached image – I think you have missed the stack function. If stack isn’t included the argument v has to be a vector.
MIke Armstrong wrote:
Jean,
Cheers for the function.
Have a look at the attached image – I think you have missed the stack function. If stack isn’t included the argument v has to be a vector.
It could be that your Mathcad version screws the work sheet.
Try to rebuild as is. The work sheet is in the other thread
"lookup: row extractor"...
Jean
That actually will not work in MC11, because MC11 does not allow stack with only one argument. This works in all versions:
Cheers for the modified function. Only just realised that you reply to the stack query.
Never mind not visiting for a week - I went to watch the match for 3 hours and couldn't keep track of this thread where I am active. Good look to new posters navigating through for the first time.
Mike
jean Giraud wrote:
... guess what !!! My stuff was before yours, and deleting my stuff delete your post message to mine.
Looks like that is true, although it is optional:
That is an extremely bad policy! If I reply to a post some of what I say may be relevant to posts other than the one that was directly replied to, and someone else should NOT be able to delete what I write!!!!!
Where has my post gone??????
Extremely bad policy. As Richard said, each post can be responding to several posts above, so why does that give the person who is directly being responded to the right to delete someone else's post?
Mike
Hah! You replied to me and are now at my mercy! Maybe I will make a copy of my reply, delete mine and yours, and then put mine back again!
MIke Armstrong wrote:
Where has my post gone??????
Extremely bad policy. As Richard said, each post can be responding to several posts above, so why does that give the person who is directly being responded to the right to delete someone else's post?
Mike
Don't worry Mike and Richard and collabs: I doubt this disaster will be noticed by the Mathcad Planet designer(s), maybe even including Mona. As long as NannyCare says"possibly answered, answered" and that there are visitors, it's all what counts ... blowing wind. The hamster algorithm [Dan's algorithm], that's what feeds this forum. Easy to repair, but will it be one day or never ? Question for Watson.
Sher. asked Watson: what do you think about the night ?
Oh ! very nice.
Only nice ?
Plenty of stars.
and .... will be nice sleep
Hey Watson ! somebody has stolen our tent.
Jean