04-04-2024 08:32 AM
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?
04-04-2024 08:49 AM - edited 04-04-2024 08:50 AM
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?)
04-04-2024 08:56 AM
If the sub arrays are different lengths you need to go through an array of clusters (which holds one 1D array each).
04-04-2024 08:59 AM - edited 04-04-2024 09:01 AM
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
04-04-2024 09:08 AM - edited 04-04-2024 09:09 AM
@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:
result:
04-04-2024 09:32 AM
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
04-04-2024 09:43 AM - edited 04-04-2024 09:59 AM
@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?
04-04-2024 09:51 AM
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
04-04-2024 10:35 AM - edited 04-04-2024 10:39 AM
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.
04-04-2024 10:40 AM
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.