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

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

Find consecutive values in a matrix

arnair81
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
LucMeekes
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:

LM_20180827_Consecutive.png

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

 

Success!
Luc

View solution in original post

9 REPLIES 9
MJG
18-Opal
18-Opal
(To:arnair81)

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

arnair81
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

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.

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

LucMeekes
23-Emerald III
(To:arnair81)

How about:

LM_20180827_Consecutive.png

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

B.png

@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?

 

 

 

LucMeekes
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:

LM_20180827_Consecutive.png

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

 

Success!
Luc

Thanks to all. It is working for me now.

review the functions

  • match
  • submatrix
Top Tags