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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

10-Marble

## Find consecutive values in a matrix

Hi,

How to write a program to find out consecutive values in a matrix.

Thanks,

Aravind

1 ACCEPTED SOLUTION

Accepted Solutions
23-Emerald III
(To:Werner_E)

Ah, thanks Werner. Forgot to clear the new string, and to do the end-check.

Here's the corrected file:

Changed the output to a transposed array, for a clearer presentation.

Success!
Luc

9 REPLIES 9
18-Opal
(To:arnair81)

Care to provide a little more clarification?  At least provide an example matrix and expected result.

10-Marble
(To:MJG)

Sorry for not being clear.

For eg. [ 1 2 3 4 7 9 10 12 15 16 19 20]. Here 1 2 3 4 and 15 16 are consecutive numbers. I want to write a general program to get only consecutive numbers for a particular matrix. Hope that helps.

Thanks

24-Ruby V
(To:arnair81)

Its not clear if you are talking of a generic m x n matrix or a simple columns vector.

Its not clear to me what exactly you mean with "Find consecutive values in a matrix"

While I am pretty sure that your problem can be solve with a small self-written function, a few examples in a demo worksheet (you have to state which version of Mathcad or Prime you are using) sure would be needed.

10-Marble
(To:Werner_E)

Sorry for not being clear.

I am attaching an image. m1pbias is a column vector and I want to find out only the consecutive numbers. for eg. 51 52 53 is one set. So is 59 60. There are others as well. I want to write a program to find them. Hope it helps.

I am using prime 4.0.

Thanks

23-Emerald III
(To:arnair81)

Note that you can set the difference that you need between 'consecutive' elements with the parameter d.

You should be able to translate this to Prime.

Success!
Luc

24-Ruby V
(To:LucMeekes)

@arnair81

What should happen if a number occurs multiple times in a row? I am aware that this will not happen in your application, but an utility function should be as complete as possible

What should be the return for the series 2-3-4-4-5 (Should it be 2-3-4, or 2-3-4-4-5, or 2-3-4-5, or ..)

Is the result as a nested vector of vector the data structure you are looking for?

23-Emerald III
(To:Werner_E)

Ah, thanks Werner. Forgot to clear the new string, and to do the end-check.

Here's the corrected file:

Changed the output to a transposed array, for a clearer presentation.

Success!
Luc

10-Marble
(To:LucMeekes)

Thanks to all. It is working for me now.

23-Emerald I
(To:arnair81)

review the functions

• match
• submatrix
Announcements
Top Tags