Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Hi,
How to write a program to find out consecutive values in a matrix.
Thanks,
Aravind
Solved! Go to Solution.
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
Care to provide a little more clarification? At least provide an example matrix and expected result.
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
How about:
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
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?
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
Thanks to all. It is working for me now.
review the functions