05-30-2018 11:25 AM - edited 05-30-2018 11:31 AM
(Sorry, still on vacation so late to the party :D)
05-31-2018 04:55 AM - edited 05-31-2018 04:57 AM
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.
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...
05-31-2018 11:32 AM
Thank you. Code attached.
05-31-2018 03:17 PM
This will do the same thing, without loops or shift registers (and without a build array inside said loop).
06-01-2018 01:56 AM - edited 06-01-2018 01:58 AM
@Zwired1 wrote:
This will do the same thing, without loops or shift registers (and without a build array inside said loop).
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.
06-01-2018 02:25 AM
BTW here's the old school version, cleaned up.
With some comment, it would be almost as good as the other method. But a bit slower in execution, I expect.
06-01-2018 11:49 AM
agreed, wiebe, they're near identical. I looked at your code and saw loops not case structures.
06-04-2018 02:43 AM
@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.
06-04-2018 12:27 PM
@Zwired1 wrote:
This will do the same thing, without loops or shift registers (and without a build array inside said loop).
I woul probably find a way to combine the top -1, the last subtraction, and +1 into one operation...
06-06-2018 03:32 AM
@altenbach wrote:
@Zwired1 wrote:
This will do the same thing, without loops or shift registers (and without a build array inside said loop).
I woul probably find a way to combine the top -1, the last subtraction, and +1 into one operation...
Like I did before (here)?