From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Decoding a Labview Code

(Sorry, still on vacation so late to the party :D)

 

  • We don't debug pictures so I would recommend to attach the VI instead.
  • Code looks quite simple, but I have the suspicion that it could be simplified dramatically. For example, there is absolutely no need to build an integer array of unknown size just to take the average later. All you need is a scalar shift register (of suitable type to guarantee that you don't get wraparound) where you sum the relevant elements and another one where you keep count. That's all you need to calculate the average, right? etc.
  • I guess this is only the tip of the iceberg of your project. Does the modification you need to do even involve this subVI?
  • What kind of "modifications" are required? (functional, cosmetic, bug fix, new feature, etc)
0 Kudos
Message 11 of 20
(1,089 Views)

Starting from the end, it finds the index of the first TRUE. Then it adds the indices until it finds a false. Those indices are averaged.

 

So it finds the index center of the last consecutive sequence of TRUE's.

 

Note the bottom shift register ("been false") doesn't do anything.

 

I think (if you posted your code, I could test that) this does the same, in a totally different way.

 

Note saying it's better per se, it will be faster on large arrays. The original with some comments won't be too bad.

Avg Index Of Last Sequence of Booleans.png

EDIT: the default in the outer case needs to be set to NaN to match the empty array behavior of the original. Devil is in the details...

0 Kudos
Message 12 of 20
(1,058 Views)

Thank you. Code attached.

 

 

0 Kudos
Message 13 of 20
(1,040 Views)

This will do the same thing, without loops or shift registers (and without a build array inside said loop).

decode.png

 

Message 14 of 20
(1,018 Views)

@Zwired1 wrote:

This will do the same thing, without loops or shift registers (and without a build array inside said loop).

decode.png

 


Your code is exactly like what I posted, with the cases deleted. Those cases are needed for the exceptional situations: when there is no true, or only one true. If you add code for those situation, you'll end up with my code.

0 Kudos
Message 15 of 20
(1,004 Views)

BTW here's the old school version, cleaned up.

Avg Index Of Last Sequence of Booleans (old school).png

With some comment, it would be almost as good as the other method. But a bit slower in execution, I expect.

0 Kudos
Message 16 of 20
(999 Views)

agreed, wiebe, they're near identical.  I looked at your code and saw loops not case structures. 

0 Kudos
Message 17 of 20
(991 Views)

@Zwired1 wrote:

agreed, wiebe, they're near identical.  I looked at your code and saw loops not case structures. 


Great, we're on the same page! As your core code is almost the same as mine, and as both where independently made, makes me think it's a good solution.

 

I'm not sure what it is about the other solution, using a loop. Guess it just feels a bit less intuitive.

0 Kudos
Message 18 of 20
(975 Views)

@Zwired1 wrote:

This will do the same thing, without loops or shift registers (and without a build array inside said loop).

decode.png

 


I woul probably find a way to combine the top -1, the last subtraction, and +1 into one operation...

0 Kudos
Message 19 of 20
(960 Views)

@altenbach wrote:

@Zwired1 wrote:

This will do the same thing, without loops or shift registers (and without a build array inside said loop).

decode.png

 


I woul probably find a way to combine the top -1, the last subtraction, and +1 into one operation...


Like I did before (here)?

0 Kudos
Message 20 of 20
(934 Views)