Skip to main content
1-Visitor
August 27, 2018
Solved

Find consecutive values in a matrix

Hi,

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

 

Thanks,

Aravind

LucMeekesAnswer
23-Emerald V
August 27, 2018

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

9 replies

1-Visitor
August 27, 2018

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

Translate
arnair811-VisitorAuthor
1-Visitor
August 27, 2018

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

Translate
Werner_E
25-Diamond I
August 27, 2018

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.

Translate
arnair811-VisitorAuthor
1-Visitor
August 27, 2018

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

Translate
23-Emerald V
August 27, 2018

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

Translate
23-Emerald I
August 27, 2018

review the functions

  • match
  • submatrix
Translate