LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create sub-arrays based on the positions of indicies in a separate index array?

Solved!
Go to solution

 I have a 1D array of index values and a 1D array of measured values. As an example:

 

Index array: 1, 2, 4, 7, 126, 127,129, 214, 215

Measurement array: 5, 6, 8, 4, 4, 9, 8, 7, 5 

 

I want to get sub-arrays of measurement array (three for this example):

 

[5,6,8,4], [4,9,8],[7,5]

 

A sub-array is generated when there is a big gap (this value is known) between consecutive elements of Index array (126-7, 214-129, this value is known, say 80).

 

How to do this in labview.

 

Thanks

0 Kudos
Message 1 of 11
(4,266 Views)

Pass both the arrays to a for loop. and compare between index values. pass these values to get subarray of your measurements

Labview user
0 Kudos
Message 2 of 11
(4,238 Views)

Can you provide with a example code.

0 Kudos
Message 3 of 11
(4,222 Views)

I have attached a vi. As per your requirement. Its a bit lengthy but probabbly you will design a better one.

Labview user
0 Kudos
Message 4 of 11
(4,212 Views)

Thanks for the help.

 

In the program second sub-array is picking the last element of first sub-array.

 

Can you do it without any timed loop (for example, using shift register).

And I need to sort and find  the maximum of each sub-array and then their average.

 

Sorry, I don't have much experience with labview.

0 Kudos
Message 5 of 11
(4,203 Views)

@Aojha wrote:

I have attached a vi. As per your requirement. Its a bit lengthy but probabbly you will design a better one.


Please, do not use this as an example of good LabVIEW code.  There is no need for the sequence structures and local variables.  The snippet below shows a much simpler, cleaner implementation.  The false case just increments the top shift register, and passes through the lower two unchanged.

create sub-arrays.png

Message 6 of 11
(4,202 Views)

Thanx Natahn,

It is a good code

Labview user
0 Kudos
Message 7 of 11
(4,197 Views)

Thanks for your help.

I tried to generate your program but there is some problem (I dont know the false case).

And I want to find the maxima of each sub-array and then find their average (this should be the final output).

 

Attached is my program.

0 Kudos
Message 8 of 11
(4,170 Views)

Drag the diagram posted by Natahnd on desktop, it will creat an image file. drag that image file in your code. you will see the code.

BTW in the false case you have to increament the index value.

Labview user
0 Kudos
Message 9 of 11
(4,165 Views)
Solution
Accepted by topic author Alice12

@Alice12 wrote:

I tried to generate your program but there is some problem (I dont know the false case).

And I want to find the maxima of each sub-array and then find their average (this should be the final output).


You have it mostly right.  I explained in my post what's in the false case: an increment (+1) for the top shift register.  The other wires pass straight through.  The image I posted is a "snippet" - it's actual code.  You can drag it into a block diagram (with some web browsers, you will need to drag to your desktop first, and from there to the block diagram).  There is a bug in the snippet creation where it does not always show cluster contents properly, and that's what happened here.  The array constant wired to the left side of the lower shift register contains a cluster containing an array of numeric values.  You will see this if you load the snippet.  I hope that you were able to understand the logic of this code as you were constructing it, but if not, please ask for an explanation.

 

From there it is trivial to find the max and averages.  Connect the output of my code to a for loop.  Inside the for loop, unbundle the array, and compute the maximum and average.  Functions to do these operations on any numeric array already exist (look for Array Max & Min, and Mean).

0 Kudos
Message 10 of 11
(4,162 Views)