LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Split an array into subarrays programmatically

Hi,

 

I have an array of data which I want to break down into 8 sub-arrays by value in the first column.

 

1. I initially remove the empty rows

2. I build a new array using a conditional for loop which holds the ID and the rows of interest.

3. I insert the ID over the redundant first column.

 

I would like to break 'output' into sub-arrays by value. I'm expecting to have 8 sub-arrays of @ 50-60 rows at the end. Any extra rows that don't fall into these sequences need to be removed. 

 

What's the best way to approach this? Code and screenshot attached.


Thanks,

 

J

 

How should I approach this?

 

Download All
0 Kudos
Message 1 of 11
(795 Views)

Hi Jee,

 


@Jee_with_a_J wrote:

I have an array of data which I want to break down into 8 sub-arrays by value in the first column.

 

1. I initially remove the empty rows

2. I build a new array using a conditional for loop which holds the ID and the rows of interest.

3. I insert the ID over the redundant first column.


I cleaned up your code a little bit:

The values in "col 0" don't look like a "sequential reference ID" to me, so maybe you need to explain your requirements better - or provide more meaningful data…

 

(As I don't have the GPower toolkit installed I had to replace the "Mode" function by a simple Mean. What result does "Mode" calculate?)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(782 Views)

If the sub arrays are different lengths you need to go through an array of clusters (which holds one 1D array each).

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 11
(773 Views)

Hi Gerd,

 

Thanks for the optimisations, I'm always learning new ways to approach things here!

 

I'm using mode to check how many elements there are in each row. So in this case  I'm expecting 100 elements (excluding 0s), but there may be some that are within a +/- (e.g. 4), so some rows might have 96/104 elements. These are then conditionally filtered in the for loop to produce a new array.

 

As for col0, these are the IDs of the extracted rows which do not contain all 0s. so the first 56 elements are sequential from 80-136 - which would be subarray 1. The next 56 elements are sequential from 209-264.

 

Hopefully that makes more sense.


J

 

 

 

0 Kudos
Message 4 of 11
(769 Views)

@Jee_with_a_J wrote:

so some rows might have 96/104 elements. These are then conditionally filtered in the for loop to produce a new array.


Looks like you needed kind of variable length arrays, here is typical design pattern already mentioned above:

snippet.png

 

result:

 

Screenshot 2024-04-04 16.06.31.png

Message 5 of 11
(751 Views)

Hi Gerd,

 

I've added some code which is getting me closer, but I think will assist in understanding what I'm trying to achieve.

 

I've added a loop to check for sequence, the boolean false results are when the array needs to be split into sub-arrays.

 

I just don't know where to go from here!


Thanks,

 

J

0 Kudos
Message 6 of 11
(718 Views)

@Jee_with_a_J wrote:

I just don't know where to go from here!


Thanks,

 

J


For some reason, your latest attachment is too new. Please "save for previous" (2020 or below) and attach again. (Also attach the missing subVI)

 

I am sure all you need is exactly one loop!

 

What is the ID you are talking about?? If it is the value of the first column, how do you know how many there are, especially since we are dealing with DBL?

 

Does the row order inside the subarray matter? can there be duplicates?

0 Kudos
Message 7 of 11
(705 Views)

Hi altenbach,

 

I've reattached..

 

The ID corresponds to a row of pixels, and the ID is generated in the middle for loop by the iteration counter. This is Col0 on the output array.

 

The row order needs to be maintained as they're adjacent rows in an image. There will never be a duplicate in col0.

 

Hopefully that clears things up... I'm doing my best to articulate it!

 

Thanks,

 

J

0 Kudos
Message 8 of 11
(698 Views)

Please stop attaching new VIs with the same name as earlier VIs. That causes infinite confusion! Each changed attachment needs a new name!

I still don't have the subVI and thus don't know what it does. It is the same as plain "mode.vi" from the normal palettes? What is a reasonable value of the +/- control? I double zero is a reasonable default value, so please set a default value before saving.

0 Kudos
Message 9 of 11
(666 Views)

Hi altenbach,

 

Apologies, I didn't realise saving for a previous version it only names the folder and not the vi!

 

Correct version should be attached now.

 

 

0 Kudos
Message 10 of 11
(663 Views)