LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I find specific value from two arrays of data

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.

 

Array of Data.png

 

 

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

0 Kudos
Message 1 of 9
(1,312 Views)

This sounds like homework. Where are you stuck, what have you tried? Have you been able to solve some part of it? Try to break the problem into smaller pieces. 

Certified LabVIEW Architect
0 Kudos
Message 2 of 9
(1,305 Views)

@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? 

Redhawk
Test Engineer at Moog Inc.

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.

0 Kudos
Message 3 of 9
(1,299 Views)

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:

 

Array.png

 

Thanks.

 

 

 

 

0 Kudos
Message 4 of 9
(1,290 Views)

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:

 

Array.png

 

- Reduanul

0 Kudos
Message 5 of 9
(1,288 Views)

Array.png

 

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? 

Message 6 of 9
(1,273 Views)

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? 

Message 7 of 9
(1,255 Views)

All code that has been posted so far is completely pointless and extremely inefficient. Some issues have already been mentioned.

 

  • To collect data in an array, appending at the end is significantly more efficient than pre-pending. You need to swap the inputs to built array.
  • All you need is check the new value. It makes no sense to re-compare all the values from previous iterations.
  • Equal comparisons on DBL values should never be done and there is a high chance that the value is never exactly -0.5 and eventually you'll run out of memory. You can e.g. check if it is between -0.49 and -0.51.
  • The built array before the graph has no purpose.
  • Why do you even need to collect and graph all data (You'll run out of memory!). To detect a ~-0.5 and display the corresponding other value does not need all the history data.
  • You can use a single complex array to collect the data if you really need to. the xy graph will understand it directly. One option would be to only collect the rare pairs where y~-0.5, for example.
  • There is a primitive to negate a value.
  • ...
Message 8 of 9
(1,245 Views)

Start with something like this....

 

altenbach_1-1625671426342.png

 

  • Generate two random numbers and negate one. (A & B)
  • If the negated value is between -0.501 and -0.499, stop the loop and display A and B.
  • (make sure to set the execution option to "clear indicators when called".)

 

Message 9 of 9
(1,233 Views)