07-07-2021 07:50 AM
Hello Folks,
I need assistance from you.
I have two arrays of data. First array (Data set A), which is generating numbers from 0 to 1. The second one (Data set B) which is generating numbers from -1 to 0. This pair of data is generating continuously until the stop button is pressed.
This is what I am trying to get:
When the value of “Data set B” becomes -0,5, I need to show the corresponding value of the “Data set A” value in the indicator (-0,5 V).
Thanks for your time.
- Reduanul
07-07-2021 07:59 AM
07-07-2021 08:05 AM - edited 07-07-2021 08:06 AM
@REDUANUL wrote:When the value of “Data set B” becomes -0,5, I need to show the corresponding value of the “Data set A” value in the indicator (-0,5 V).
What do you mean "the value"? The average of "Data set B"? The last value to be added?
Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.
07-07-2021 08:20 AM
Hello thols,
It's pity that maybe this a simple task but messed up with the logic maybe. I tried a bit but could you be able to find the solution.
Here was my effort:
Thanks.
07-07-2021 08:27 AM
Hello FireFist-Redhawk,
Not avarage of "Data set B" ! Only the value of -0,5 from Data set B.
So there will be a loop that will look for -0,5 value and when it will find the value, the loop will stop and give the corresponding Data set A value to the indicator.
That was my effort:
- Reduanul
07-07-2021 08:42 AM - edited 07-07-2021 09:04 AM
Hi Reduanal,
This solution is pretty inefficient. For each iteration of the main while loop, the searching loop will run n+1 times to find the element. The way you're building the arrays will cause the new value to be the first element in each array. You could check if the 0-th element of Data Set B is -0.5 instead of searching the entire array for -0.5 or even check if the new number you're adding to Data Set B is -0.5 before adding it. That would save a lot of time. As Data Set B gets larger and larger, this loop will take longer and longer to run because the entire array is being searched with each iteration.
Also, generating random numbers and looking for exactly -0.5 could take a very long time and require many iterations. Do you need to generate the numbers randomly? Or alternatively, could you put a tolerance on the -0.5 value, like -0.5 +/- 0.001?
07-07-2021 09:05 AM - edited 07-07-2021 09:06 AM
I won't pretend the aren't lots of issues here, but lets start with the basics. And, if you were to turn on "Highlight Execution" you may have seen one issue right away. Once data enters the inner "While Loop" it will NEVER exit unless if finds EXACTLY -0.5. Dataset B is Auto- Indexed, however when it run out of values it just starts feeding zeros into the while loop. It will never stop looking for -0.5 in order for that loop to stop. A secondary stop function, probably based on the number of values in the array, needs to be added for the inner loop.
Another issue you will run into later is that comparing a DBL to another DBL for being equal is mostly a fruitless exercise. You need to constrain how many digits to the right of the decimal point (comma in your case) to actually use. The number -0.5 is actually -0.500000000000000000 (I think that is enough zeros.)
By the way, any reason you have not wired Data Set A to the input of the Index Array function? Along with the output of that same function to the indicator?
07-07-2021 10:03 AM - edited 07-07-2021 10:12 AM
All code that has been posted so far is completely pointless and extremely inefficient. Some issues have already been mentioned.
07-07-2021 10:25 AM - edited 07-07-2021 10:28 AM
Start with something like this....