05-27-2016 08:19 PM
Hello,
Just need a quick help. I have 3 arrays. I have some data in Array1 wich has 10 columns.
I am taking the value in the first columns of Array1 and compare them with the values in Array 2. For example, from array 1, if 133.38 is between 30.00 and 230.00 (of arry 2), then put 50.0 (of array 3) in the last column of Array1.
It means simply, take each value in Column1 of Array1, check in array 2 the range of that value, and then outpu in the last column of array 3 the value in the index of array 3 corresponding to the index of the lower limit.
Example 2. considering 400.00 in column1 of array1, compare its range with the value in array2. we can see that 400 is between 230 and 1000.00 (in array2), so then we have to put 70.0 in the last culomn of Array1.
Thank you for this help.
Solved! Go to Solution.
05-27-2016 08:39 PM
Nice homework problem. Sometimes it helps to "divide and conquer".
First, think carefully about the first part of your problem. You have an Array (2) -- are you guaranteed that it is in ascending order? If presented with a number and Array 2, what output do you want? Think about all the cases (let's assume that the array is "equal or ascending") -- what if your number is less than all the number in the Array? Greater than all the numbers? Equal to one of them? Any other case to consider?
Write a little bit of LabVIEW code to encapsulate this bit of the problem.
Now you have a value, and another Array (3). What do you want to do with your value and the Array? Will you always be able to return a number? Write down this little bit of logic. How does it "connect" with the earlier bit you did?
OK, so where did we get the original number we used with Array 2? What do we want to do with the number we get from Array 3?
Put everything together, and try it out. Does it work?
If you do it yourself, you will learn something. IF ONE OF US DOES IT FOR YOU, you will learn How to Cheat.
Bob Schor
05-27-2016 08:50 PM - edited 05-27-2016 08:51 PM
Use Threshold 1D Array to get the index of where your first value will be relative to array 2, round down (toward -Infinity) and index from Array 3. Relplace the corresponding cell in array 1.
05-28-2016 10:27 AM
I would do the same as Tim, but since you want to modify array 1, just write to a local variable of it at the end.
Depending on the quality of the data, you might also need to handle some special cases and Bob already hinted to some of them.
You need to define the output if e.g. the initial value is outside, e.g. zero or 2000. What if the value is an empty string or not numeric?
What if the 2D input array only has 9 columns initially. Now Tims' code would fail because you cannot replace what does not exist.
You need to make the code bulletproof so LabVIEW can tell if something is wrong and return an error.
Now let's look at your original program (ignoring all program logic and just looking at the general coding techniques!):
05-28-2016 02:08 PM
Thanks a lot. Simply efficient.