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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Extracting Rows Based on Array Values

LearningENG11
4-Participant

Extracting Rows Based on Array Values

I have an array with values and I want to extract the rows, from a different matrix, that correspond to the values of the array. Any ideas on how that is possible? Right now the row extraction command (CRTL+SHIFT+r) will only accept integers.

 

Thank you in advance

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:LearningENG11)

To select an integer, klick on it. That is the standard Microsoft answer.

From where would you want to select an integer. You show a number of pictures, with several structures that contain integers.

 

I still think that your task is (the same as what is) explained, and solved, in this thread: https://community.ptc.com/t5/Mathcad/Retrive-horizontal-matrix-rows-based-on-vector-in-Mathcad/m-p/797732#M201303

For you convenience I've translated Stuart's worksheet to Prime6, so you should be able to load it.

Did you look at it? Does it meet your needs? If not, then as Werner already indicated: explain clearly, by a simple example, what you do need.

Preferably attach that simple example as a Prime Worksheet, NOT just a picture.

 

Success!
Luc

View solution in original post

12 REPLIES 12

Hi,

Can you provide an example for more clarity?

Cheers

Terry

Hi, I have a series of loads from load combinations that are placed on my model. I export those forces into excel and then bring them into MathCAD as an array. Right now, I check by hand, what I think will be the limiting factors, run the calculations for those scenarios and then see what it returns. What I want to do is run all load combination calculations at once and have MathCAD tell me which load combination(s) are the limiting factor(s).

> I have an array with values and I want to extract the rows, from a different matrix, that correspond to the values of the array. 

Still not clear for me what exactly this should mean.

Maybe you would be better off if you provide one or two specific numerical examples, each showing the matrix, the vector AND the result you would like to see.

Hi Werner,

 

Each force is associated with a Load Combination (string). I want to know which Load Combinations cause the system to fail. I attached snaps of my worksheet below.

LucMeekes
23-Emerald III
(To:LearningENG11)

"Right now the row extraction command (CRTL+SHIFT+r) will only accept integers."

And that is for good reasons. Rows and columns of arrays are numbered sequentially, similar to platforms on a train station. As there is no platform 9¾ on London's Kings Cross station (except of course if you're a wizard), there is no row 3.14 in an array between rows 3 and 4..

 

Is your problem related, or similar, to this: https://community.ptc.com/t5/Mathcad/Retrive-horizontal-matrix-rows-based-on-vector-in-Mathcad/m-p/797732#M201303 ?

 

Luc

LucMeekes
23-Emerald III
(To:LearningENG11)

Decided to try some magic...

LucMeekes_0-1657708431635.png

Success!
Luc

Hi LucMeekes,

 

I have PTC Prime 6.0 so I can't see the file but thank you for your help, much appreciated! I was wondering if you could perhaps explain the function? I am new(er) to MathCAD and was hoping you could guide me through on what you did.

 

If not, I understand but thank you once again.

LucMeekes
23-Emerald III
(To:LearningENG11)

The file was saved from Prime 6, so it should open in Prime 6 without problems. If it doesn't, let me know.

 

The function treats the values in the vector l as a list of row indexes. When an index is an integer number, it will fetch that row from the matrix M. If the index contains a fractional part, it will take the weighted average between two rows, as weighted by the fractional part.

So for 0.5 you get the average of (the values of) row 0 and row 1.

 

Success!
Luc

HI LucMeekes,

 

Thank you for the explanation! If I wanted to select a integer from this, how would I do that?Question1.PNGQuestion2.PNGQuestion3.PNG

LucMeekes
23-Emerald III
(To:LearningENG11)

To select an integer, klick on it. That is the standard Microsoft answer.

From where would you want to select an integer. You show a number of pictures, with several structures that contain integers.

 

I still think that your task is (the same as what is) explained, and solved, in this thread: https://community.ptc.com/t5/Mathcad/Retrive-horizontal-matrix-rows-based-on-vector-in-Mathcad/m-p/797732#M201303

For you convenience I've translated Stuart's worksheet to Prime6, so you should be able to load it.

Did you look at it? Does it meet your needs? If not, then as Werner already indicated: explain clearly, by a simple example, what you do need.

Preferably attach that simple example as a Prime Worksheet, NOT just a picture.

 

Success!
Luc

I am not sure what your function "Exctract" is supposed to do and unfortunately you don't show the error message which is thrown when you call "Exctract".

So just some remarks:

"match" returns indices and these always are integers. This means that your vector "Fail" consists of all integers and therefore "Fail.i" is always the very same as "floor(Fail.i)".

This means that "(Fail.i - floor(Fail.i))" simplifies to zero and your "if" condition has no effect as you always would get the row with number Fail.i of vector "vx".

I guess that the functions fails because of an index out of range?

 

I also don't understand the condition in your "if" statement:

if (Fail.i>=ORIGIN+rows(vx)-1, ....)

which, as I see it, is equivalent to

if (Fail.i = last(vx),...)

because no value in "Fail" can be larger than the last index of vector "vx".

Looks like you simply used Luc's function without understanding what it actually does.

Its still unclear to me what actually you want to achieve!

 

And, as Luc already said, don't post only pics but post the worksheet as well. If for some reason you are not allowed to post the sheet you may create a simplified stripped down dummy sheet with dummy data which shows the problem and state clearly what exactly you are looking for.

If you are looking for a vector of strings which only show which Load combinations failed, you may use

Werner_E_0-1657819734057.png

A shorter version is

Werner_E_1-1657820028724.png

 

 

 

Hi Werner and Luc,

 

Thank you all very much for the help. I was able to solve the issue by taking the MathCAD file that LucMeekes linked and adjusting it a little for my purposes. I have noted it as the solution. I am not very good at MathCAD (or coding in general) and have been trying to use it more and learn. Next time Ill be sure to upload a copy of the MathCAD sheet when I need help. 

 

Thank you both again for the help.

Announcements

Top Tags