LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create subarrays of sequential integers?

Solved!
Go to solution

Hello,

 

I was wondering how to do something.

Let's say for example that my input is an array of numbers. One thing I know is that the integers are all sequential, but with gaps inbetween. Something like this:

 

3,4,5,9,10,11,12,16,17, 18,....

Not so important for this issue, but if you want more background : Each of these numbers correspond to an index of another array, which is the analog input array. 

 

 

What I want to get is all the subarrays, without the gaps, so for the example above:

3,4,5

9,10,11,12

16,17,18

.

.

.

Background again: Later I will have to compare the values to which these numbers correspond to see which one is the highest and just keep the index of the highest number.

 

If you don't have time to give an example code, I'd be delighted with a simple idea too 🙂

 

I've tried putting in my array into a loop twice, checking one value incremented by one with the next value, but all of this gets very complicated when trying to build arrays again. I was thiking of using "index array" to get the sub arrays or "split 1D array" to do it instead. 

 

Thanks in advance,

 

David.

0 Kudos
Message 1 of 21
(1,943 Views)

just an idea for you to try. step through the array starting at index 0. find the difference between  the current element and the previous element (need a shift register). If this is greater than 1 you have found the start of the next subarray. The loop count will give you the index to split the main array. repeat until main array been examined. 

 

There may be some bugs in the logic but hopefully given you an idea of a way to approach it.

 

 

TD 

Please remember to accept any solutions and give kudos, Thanks


LV 8.6.1, LV2010,LV2011SP1, FPGA, Win7
Message 2 of 21
(1,938 Views)
I'm on my phone so I can't give you example code. You cannot have an array of arrays. I put an idea for that on the idea exchange. What you need to do is output an array of clusters. The cluster contains an array of integers. Loop through your input array and build an array. If the current number is greater than the previous +1 bundle the array and append it to the array of clusters. You could use a 2d array but only if all rows will be the same size. Let me know if you have questions. I might be able to work up a quick example later.
=====================
LabVIEW 2012


0 Kudos
Message 3 of 21
(1,933 Views)

I don't really understand what you mean. I'm currently trying out Tdarkins way though.

You're saying that won't work though, aren't you ?

0 Kudos
Message 4 of 21
(1,929 Views)

not sure a cluster of arrays would be ideal, i am presuming the values in the subarrays will inturn be used to index other arrays. the arrays could be placed into a queue  (producer/consumer setup).

 

TD 

Please remember to accept any solutions and give kudos, Thanks


LV 8.6.1, LV2010,LV2011SP1, FPGA, Win7
0 Kudos
Message 5 of 21
(1,927 Views)

@Pladio wrote:

I don't really understand what you mean. I'm currently trying out Tdarkins way though.

You're saying that won't work though, aren't you ?


What do you want the function to  output? It sounded like you want it to output several arrays from one input array. LabVIEW does not support arrays of arrays so you would need an array of clusters of arrays. Of course you could output an array containing the indexes of the "subarrays". That is another way to do it.

=====================
LabVIEW 2012


0 Kudos
Message 6 of 21
(1,917 Views)

I've attached screenshots. Is that what you meant ?

It seems to be quarter-working ... It manages to get 2,3,4,5 and then fails with the rest. I've probably done something wrong, but it seems to be going in the right direction. I'll try finding out what the problem is, but I might not be able to, so I won't mind more help 🙂

 

Thanks 🙂

Download All
0 Kudos
Message 7 of 21
(1,912 Views)

the method i outlined will split the array where you would like, but does not detail what happens to the data next, steves right LV does not allow array of arrays, so you will have to decide what to do with the sub arrays, a cluster of arrays is one way, placing them in a queue another, or you could use the information in them straight away amoungst other methods

 

TD 

Please remember to accept any solutions and give kudos, Thanks


LV 8.6.1, LV2010,LV2011SP1, FPGA, Win7
0 Kudos
Message 8 of 21
(1,911 Views)

TD, it doesn't seem to be splitting it correctly yet though. I might have a mistake as I outlined in my previous reply. I'm trying to figure it out.

0 Kudos
Message 9 of 21
(1,906 Views)

I was aiming to make some suggestions that would help you work it out instead of posting a solution, by the sounds of it you have an idea of how to do it  its just the actual implementation, so you should be able to work it out

 

TD 

Please remember to accept any solutions and give kudos, Thanks


LV 8.6.1, LV2010,LV2011SP1, FPGA, Win7
0 Kudos
Message 10 of 21
(1,903 Views)