10-31-2011 05:46 PM
Im wondering if its possible to search a 1D array for a value, if not found, then to find the closest match. Im using "double" data type and i need atleast a 4 decimal point accuracy in the search.
For now, im rounding the decimal values to the closest integers, but it is not efficient at all. Im getting a lot of undesired spikes in the plot. I need to be able to search decimal points. I found this function "Approx Equals.VI" from a previous thread. Even that uses the concept of rounding the digits.
I have attached 3 VIs. The "0.8 & 0.4.VI" is the one i made, just by rounding the decimals to closest digits.
The "Approx Equals" is the one i found online.
The 3rd one is the one i was trying to mess with so that i can find a closest match.
Is there a trick to get around this?
Thank you,
Eureka
Solved! Go to Solution.
10-31-2011 06:04 PM
10-31-2011 06:42 PM
When I need to do this, I use Threshold 1D Array and Interpolate 1D Array. Usually, I am using them together, but in your case, you may just need the first one. You may need to sort the array for your case. The output of the Threshold can be rounded up or down to find the closest point. Since LV does the interpolation, doing a "normal" rounding will get you to the closest index.
11-02-2011 06:07 PM
Matthew,
Thats a beautiful idea, i did that. Im not getting the desired output. Guess im missing something fundamental...Im able to read the index, but im missing something...thanks for the idea, it was simple and efficient.
11-02-2011 08:14 PM - edited 11-02-2011 08:15 PM
Here's a simple example.
11-02-2011 08:23 PM
If your data is more complicated, post a copy of the dataset.
11-03-2011 04:58 PM - edited 11-03-2011 04:58 PM
Matthew,
My data is a bit complicated.
As a first step, i need to separate the data according to the "Loop Number". I did that part and i have the index at which each and every loop begins and ends.
Next, for each and every loop, i need to search for "Step Type #3" and find the index of that location. Im able to do that as well.
Now, for the index value obtained form the "search for 3" function, i need to move exactly one index up(decrement by 1) and get the "Voltage" at that index. Yes, im getting the value, thats not a problem.
Let us say the Voltage value at that index is X, i need to find the index at which the "Voltage" value drops to "0.9*X" & "0.7*X". (Im trying to find the slope of the array). And, i need to read the "Test Time" column for the 2 index values so that i can find the (change in voltage)/(change in time) ratio. This is where im having a problem, if i round the values to the closest integers, it works, but the values are not even close to accurate.
I used your logic, i.e., i subtract "0.9*X" from the entire array, and read that index as the closest match. And i give that in a for loop so that it performs the same for every "Loop Number". Im not able to find the correct index values here.
11-03-2011 06:24 PM
This VI uses the first step type 3 in your data. Since you said you can get the data, you can drop this into the VI.
At the end where I calculate slope, you can use Linear Fit if you have Full or Professional LabVIEW.
11-04-2011 02:25 PM
Matthew,
That was a brilliant idea, it worked perfectly after adding an index function and an absolute sign function. Wish i could give 1000 Kudos. Awesome...
Thank you,
Eureka
11-04-2011 02:56 PM
@Eureka wrote:
Matthew,
That was a brilliant idea, it worked perfectly after adding an index function and an absolute sign function. Wish i could give 1000 Kudos. Awesome...
Thank you,
Eureka
You Can!
Stop before your mouse hand starts to ache.
Ben