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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Finding max index on imported matrix

DarKilleR
1-Visitor

Finding max index on imported matrix

Hi, i'm sorry for my bad English.

I have a file Mathcad that calculates every meter the evolution of the bending moment, shear and reactions during an incremental launching bridge.

This file, save 3 file .txt with a big matrix (221x263) (one for banding moment, one for shear and one for reactions).

I need to create e new file that import bending_moment.txt and find the maximum value in a rows and tell me the index about this max value.

I tray to use the command match....but this work with a smal matrix that i have manually created, and he don't work with the imported matrix.

Find the max value and his index is important for me, because i need this information for apply some formulas from Eurocode!

Thanks

Marco

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:DarKilleR)

Marco Mori wrote:

I use this sintax but it doesn't work.

Wrong! It works pefectly and the same way as in your smaller example at the top!

Because the nested vector is so big, Mathcad (display style is set to automatic) changes the style to table as this display format is scrollable. You may set display format it to matrix but you won't be happy if you do 😉

As you create a nested set of Matrices, in table mode Mathcad won't expand the inner matrices and just show their size ([264,1] means 264 rows, 1 column).

Look at the screenshot for selected rows:

row 185, a 1x1 matrix containing the index (115) of the max element of that row

row 188, a 2x1 matrix, because the maximal element (3.118) occurs twice in that row and match will return both indices (144 and 115) in a vector. Thats the reason you have nested arrays and thats also the reason match returns a 1x1 matrix and not a single scalar if the value is found only once. You may have noticed in my post above that I had added "[0" at the end. As you have changed ORIGIN to 1 in your sheet, you will have to change it to "[1" and it will select the first element of the vector returned by match, That way your Max_index will be a vector consisting of just 264 scalars. Maybe that it what you want to have, I don't know.

Now for the funny part, row 40 (and this applies to every of the first 40 rows). These rows consists of zeros only, so the maximum is zero and match() returns a 264x1 vector because the maximimum occurs at 264 positions. Could it be that that was the reason you thought it didn't work?

28.04.png

View solution in original post

4 REPLIES 4
Werner_E
25-Diamond I
(To:DarKilleR)

Without seeing the data and the file where your approach fails we cannot tell what might be wrong.

The usual way to get the index would be

inedex := match(max(data), data)[0

I use this sintax but it doesn't work.

I annext an exemple.

File mathcad and file .txt must stay in the same path for work

Thanks for your time

Werner_E
25-Diamond I
(To:DarKilleR)

Marco Mori wrote:

I use this sintax but it doesn't work.

Wrong! It works pefectly and the same way as in your smaller example at the top!

Because the nested vector is so big, Mathcad (display style is set to automatic) changes the style to table as this display format is scrollable. You may set display format it to matrix but you won't be happy if you do 😉

As you create a nested set of Matrices, in table mode Mathcad won't expand the inner matrices and just show their size ([264,1] means 264 rows, 1 column).

Look at the screenshot for selected rows:

row 185, a 1x1 matrix containing the index (115) of the max element of that row

row 188, a 2x1 matrix, because the maximal element (3.118) occurs twice in that row and match will return both indices (144 and 115) in a vector. Thats the reason you have nested arrays and thats also the reason match returns a 1x1 matrix and not a single scalar if the value is found only once. You may have noticed in my post above that I had added "[0" at the end. As you have changed ORIGIN to 1 in your sheet, you will have to change it to "[1" and it will select the first element of the vector returned by match, That way your Max_index will be a vector consisting of just 264 scalars. Maybe that it what you want to have, I don't know.

Now for the funny part, row 40 (and this applies to every of the first 40 rows). These rows consists of zeros only, so the maximum is zero and match() returns a 264x1 vector because the maximimum occurs at 264 positions. Could it be that that was the reason you thought it didn't work?

28.04.png

I want married you!

Yeah, now it works perfectly!

This was the problem:

Thats the reason you have nested arrays and thats also the reason match returns a 1x1 matrix and not a single scalar if the value is found only once. You may have noticed in my post above that I had added "[0" at the end. As you have changed ORIGIN to 1 in your sheet, you will have to change it to "[1" and it will select the first element of the vector returned by match, That way your Max_index will be a vector consisting of just 264 scalars. Maybe that it what you want to have, I don't know.

I spent two weeks trying to solve this problem.

Thank you very much for your help!

Announcements

Top Tags