LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Decoding a Labview Code

(Sorry, still on vacation so late to the party Smiley Very Happy)

 

  • 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)

LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 11 of 20
(322 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
(291 Views)

Thank you. Code attached.

 

 

0 Kudos
Message 13 of 20
(273 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
(251 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
(237 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
(232 Views)

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

0 Kudos
Message 17 of 20
(224 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
(208 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...


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 19 of 20
(193 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
(167 Views)