LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

turn array of integers into a ranges list

Solved!
Go to solution

I am looking for a clean way to turn an array of integers into a ranges list.

turning thistshurtz_0-1591732469530.png into this tshurtz_1-1591732544909.png or at least this tshurtz_2-1591732838357.png

 

I am hoping there is a VI already somewhere in the bowels of Labview that I can use as this is essentially what is happening in the case structure selector label if you list many integers and some are consecutive.

 

Anyone know where I might find this magic vi? I can write my own but if its already available all the better. 

 

 

0 Kudos
Message 1 of 7
(3,781 Views)

I doubt it,  you'll likely have to code it yourself.

Should be a fairly simple loop with just a couple case structures.

 

You need to know when you are starting a run of numbers, ending a run of numbers, or still in the middle.

 

Step through element by element.  If the next element is equal to the current element + 1, you know you are in a run.

0 Kudos
Message 2 of 7
(3,772 Views)

I know the case structure will automatically do that for you.  I wonder if there's a way to leverage that information somehow...

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 7
(3,740 Views)

I made this ages ago.

"If you weren't supposed to push it, it wouldn't be a button."
Message 4 of 7
(3,724 Views)

@tshurtz wrote:

 

Anyone know where I might find this magic vi? I can write my own but if its already available all the better. 

 


I am sure this has been solved before here in the forum. But should be trivial to implements if we can make certain assumptions:

 

  • Is the array guaranteed to be sorted?
  • Are there no duplicate elements?

 

 

Assuming the input is clean, this might work for you. There are many other ways.

 

altenbach_0-1591782177301.png

 

 

0 Kudos
Message 5 of 7
(3,650 Views)
Solution
Accepted by topic author tshurtz

ranges.png

Thanks again 

0 Kudos
Message 6 of 7
(3,623 Views)

As I said, it really depends how clean the input array is and additional code might be needed.

 

One request thought. Please give a VI a new name when attaching a new version. It can lead to serious confusions if a thread contains multiple different VIs, all with the same name.

 

At this point I would suggest to turn it into a malleable VI (vim), correctly accepting any integer datatype. (only available in recent versions, but alone worth the upgrade!)

0 Kudos
Message 7 of 7
(3,614 Views)