LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can someone please help me!!!! Would you help me make this VI simpler?

Solved!
Go to solution

I am collecting a group of 5 elements from a 1D array  and do the sum of every group, then place the results of the sum into a 1D array. By looking at the VI attached, you'll know what I mean. 

So my question is  if I have to do the same thing indefinitely, what can I do to not keep using array subsets and sum blocks over and over? I do not want to use millions of "array subset" and "sum" blocks on my block diagram. I tried using shift registers and it did not work for me. I am stuck.

Can someone please help me?

 

0 Kudos
Message 1 of 10
(1,111 Views)
Solution
Accepted by topic author GRCK5000

Hi,

 

Please always make a stop condition in a While loop.

You want to do an action X times ==> it's time for a loop and here the for loop can be your friend

Just conceptualize what you have done to make it as a loop.

arr.png

 

PS: I'm sure it can even be better than that.

Message 2 of 10
(1,099 Views)

Unless I am gravely mistaken, there is a Collector on the pt by pt pallet. 

 

Otherwise, use Quotient and Remainder( i+1, samples to sum) drive a case off Remainder (0 and Default cases) do nothing in default, in case Remainder = 0 resize array(samples to sum, Quotient) Sum the resulting 2D array.

 

Yes, defaphe, the sum array elements belongs after the for loop.

 

NOTE: That is not optimal! I can't see the OP's vi so I'm just not sure what exactly is desired or how many pts accrue each time the vi is called.


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 10
(1,075 Views)

Try something like this (You probably don't need the lower shift register and the indicator for the last five values, but they are useful for debugging):

 

altenbach_0-1644853861199.png

 

 

Some quick notes:

 

  • Any toplevel while loop needs a wait. You don't want to spin it billions of times per second growing arrays forever.
  • Building arrays indefinitely is never possible, because you'll run out of memory way before that.
  • "Insert into array" is not the correct tool to build an array. Try "built array".
  • Your lower shift register is the same as [i] and thus not needed.
  • etc.

I recommend to start with the learning resources listed on the top of the forum.

 

Message 4 of 10
(1,048 Views)

Thank you very much!!!! This solved my problem. Thanks for the advice!

0 Kudos
Message 5 of 10
(987 Views)
Solution
Accepted by topic author GRCK5000

Even simpler would be to just accumulate the sum of five in a scalar shift register.

 

altenbach_2-1644854554730.png

 

 

 

Message 6 of 10
(1,030 Views)

Thanks Altenbach. You are awesome!

0 Kudos
Message 7 of 10
(1,018 Views)

@altenbach wrote:

Try something like this (You probably don't need the lower shift register and the indicator for the last five values, but they are useful for debugging):

 

altenbach_0-1644853861199.png

 

 

Some quick notes:

 

  • Any toplevel while loop needs a wait. You don't want to spin it billions of times per second growing arrays forever.
  • Building arrays indefinitely is never possible, because you'll run out of memory way before that.
  • "Insert into array" is not the correct tool to build an array. Try "built array".
  • Your lower shift register is the same as [i] and thus not needed.
  • etc.

I recommend to start with the learning resources listed on the top of the forum.

 


I knew something about that example bothered me and I suggested using i++ as the dividend into Q&R for a reason.  It actually took me a day to percolate a pot of coffee and engage brain:)

 

The case selector! You used cases for default and CONST:Divisor--. That assumes Divisor will never be turned into a control.

 

Its not often I catch you missing a trick.  (Probably a bad planetary alignment) 


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 10
(934 Views)

@JÞB wrote:
Its not often I catch you missing a trick.  (Probably a bad planetary alignment) 

 

I was fully aware that my code is not entirely scalable. I intentionally kept it simple so the OP does need to herd too many cats. :D.

 

(Possibilities are to use a boolean for the case structure that depends on a comparison of R and the size or we could do a [i]+1 before doing Q&R (because the order does not matter for averaging) and make the special case 0, which will be independent of the averaging size (This was actually how I wrote it first but I changed it because it might be confusing that the "array of five" does not fill in order). Real scalable code would allow changing the averaging length on the fly, requiring special handling for when it gets bigger or smaller. Let's not go down that rabbit hole. 😄 )

 

In any case, my second code (Scalar accumulator) is preferable and similar adjustments can be made there too).

0 Kudos
Message 9 of 10
(916 Views)

Altenbach is the king of labview, labview master 💪  

0 Kudos
Message 10 of 10
(891 Views)