LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reset array after 4 values reach

 

Hi all, I need a litle bit help with my program. I compare current and previous value of signal with shift register, if current value is different from previous it give me False for case structure and then I am storing current value to array (values in array are 0 or 1 or 2), but I need store only 4 values in array which I want compare with other array and then reset this array with 4 stored values. The values are periodically repeating, so perhaps reseting array after some specific value (lets say 2) is reached could be better solution but I need help how I can do it.

 

Thanks in advance

 

Mark

 

 

image.pngimage.png

 

0 Kudos
Message 1 of 7
(1,230 Views)

I can use element Array size and then if number of values in array will be equal to 4 then I can reset the array. But how can I reset array? 

 

Thanks

0 Kudos
Message 2 of 7
(1,195 Views)

Please attach your VI instead of pictures.

What does "reset" mean? Set the size back to zero? Since the size can only grow after a new element is added, should the array contain the new element or no elements after "reset"? What is the max array size?

 

(This seems like a trivial problem. Have you done any basic tutorials. Why is one shift register not initialized? Why is there a coercion dot? Why is the indicator terminal inside the case structure? Why is there no way to stop the VI? What determines the lop time? To append an element to an existing array, "built array" is the correct function, not "insert into array". What is the purpose of this exercise? Maybe there is a better solution overall for whatever you are trying to do here.)

 

0 Kudos
Message 3 of 7
(1,155 Views)

Hello,

 

yes, for reset I mean size back to zero. I tried something and this solution works for me.

 

Best Regards,

 

Mark

 

image.png

0 Kudos
Message 4 of 7
(1,054 Views)

Hi Mark,

 


@MarkMc20 wrote:

yes, for reset I mean size back to zero.


IF ArraysSize >= 5 THEN
  array := InitArray(size=0)
ENDIF

Instead deleting elements from an array you can also use the InitArray function to create an empty array. (Or use an empty array constant, the compiler will most probably do the same…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 7
(1,050 Views)

@MarkMc20 wrote:

yes, for reset I mean size back to zero. I tried something and this solution works for me.

 


No, just no!!!

 

  • Your upper shift register is still not initialized.
  • You still have coercion dots
  • You still use insert into array instead of built array
  • To reset the size to zero, all you need in an empty case with the output tunnel set to "use default if unwired".
  • You only need to test the size when a new element is appended, not with every iteration.
  • You still have not answered any of my other questions or explained the purpose for all this. I get the feeling that you are trying to solve a problem that has much better solutions of approached quite differently.,
  • You still only show us pictures instead of attaching a VI.
  • ...
0 Kudos
Message 6 of 7
(1,038 Views)

Maybe something like this? (I still believe you are trying to solve the wrong problem here!)

 

altenbach_0-1620662893855.png

 

(Since you seem to prefer pictures, I am not attaching a VI 😉 )

 

(You need to decide how you want to initialize the scalar shift register. It probably would make more sense to make an array with the new element once the size would be exceeded so modify the inner case (currently empty) accordingly if desired.)

 

 

0 Kudos
Message 7 of 7
(1,036 Views)