LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

arrange a 1d array into a matrix based on the sum of rows

I have a 1d array of data such as the following

 

44.8677

44.3500

44.8687

44.8529

44.8688

44.9654

 

I need these values inserted into an n dimensional matrix for instance 2x3 where the sum of the rows are as equal as possible.

0 Kudos
Message 1 of 6
(1,351 Views)

Do you have a problem figuring out an algorithm or implementing it in LabVIEW?

What have you tried?

 

What is the maximum number of elements?

0 Kudos
Message 2 of 6
(1,338 Views)

I think im close but missing something big. My approach is to randomize the list then put it into a 2x3 array which would then get the differences followed by the largest difference then i wanted to use a shift register or feedback node to do the process again if the next randomized arrays largest difference was smaller then the last it wins. Maybe its late but im stuck.

0 Kudos
Message 3 of 6
(1,310 Views)

Wouldn't it be logical if you sorted the list from smallest to largest, then filled the 2-D array with the smallest and largest value in the first row, the 2nd largest, 2nd smallest in the 2nd row,  and the remaining 2 elements in the 3rd row, that would have the least differences between the sums?

Message 4 of 6
(1,298 Views)

works for me!

0 Kudos
Message 5 of 6
(1,235 Views)

@Pohlr1 wrote:

I am glad you solved your problem, but your initial code has serious general flaws that should be mentioned. Hopefully, your final solution is a bit more polished. Feel free to attach it.

 

Now some comments to the attempt you posted.

 

  1. Not sure why you need the one-iteration FOR loop. It would be sufficient to anchor the shift register on the outer loop (initialized with +inf, of course).
  2. Currently, your shift register is also uninitialized, meaning on the second run you might get unexpected results, depending on input.
  3. There is no need to wire the indices of index array if you want the elements in order.
  4. Your number of columns is variable, so why are you only looking at three?
  5. If you do randomized trials, 100 iteration might not be sufficient. You might need an infinite number.
  6. You can easily reduce the number of wire bends and hidden wires to make the code more readable.
  7. Your blue controls need to be outside the loop because their values should be constant during execution.
  8. Shouldn't you verify that the product of dimension is equal to the input array size?
  9. While you'll get a estimate of the lowest value, your code cannot tell what the final arrangement actually is
  10. etc.

 

0 Kudos
Message 6 of 6
(1,224 Views)