02-20-2019 01:45 PM
Hi,
I'm trying to do in Labview but I'm not sure how write it. Here is the problem to solve:
A: a big array of single precision values
limit: a 99x1 vector of integer values (can be single or double if simpler)
v: a 100x1 vector of single precision values
result: An array the same size as A
The first step, I want to take all the values of A under the first value of limit and multiply it by the first value of v and put it at the same index in the result array. Afterward, I want the values of A greater or equal to the first value of limit but lower than the second value of limit and multiply it by the second value of v. Let's try a simple example to make it more clear
A = [1,2;6,3]
limit = [1,3,5,7,8,9]
v = [11,12,3,8,9,4,85]
-No values of A under 1
-Two values of A, (1 and 2), between 1 and 3, so I multiply them by 12.
-One value of A, (3), between 3 and 5, so I multiply it by 3.
-One value of A, (6), between 5 and 7, so I multiply it by 8.
-No other values are greater than 7.
result = [12,24;48,9]
Any efficient way to do it?
Thanks
RMT
Solved! Go to Solution.
02-20-2019 02:00 PM
Whatever you are trying to do is very confusing.
Since you are only talking about 100's of elements in an array, not very much by PC standards, I wouldn't worry about efficiency. Just worry about making your code work.
Take what your wrote down in text and make a flowchart or pseudocode out of it so the details of each step are clear. You'll have several loops and conditional statements. When you talk about "between", make sure you are clear on whether that is inclusive or exclusive. For example, you say you have 2 values between 1 and 3, that are in the limites, (1 and 2). But you don't include 3. But then you do say you have the 3 between between 3 and 5. So for a value to be "withing the limits" does it have to meet the equation lower <= value < upper? (Look at in range and coerce and its limit settings.)
Is "A" a 1-D array or a 2-D array?
Once you have it drawn on paper, then start executing it in LabVIEW code.
02-20-2019 02:34 PM - edited 02-20-2019 02:36 PM
(Note that you have 1D arrays. 100x1 would indicate a 2D array with one row/column. Don't confuse the two)
Sorry, posting by phone. Can show some example code later...
02-20-2019 03:38 PM - edited 02-20-2019 03:52 PM
Sorry I really have no good way of explaning it.
A is a big 2D array. I gave a small array as an example. Since I need to compute it very fast, optimizing my code is an issue.
Imagine that I'm putting all the values of A in an histogram with 100 columns. Depending of which column the value falls in, I want to operate a different math operation and have the result of the operation at the same index the value came from.
I've added a clearer example in pdf.
02-20-2019 04:21 PM - edited 02-20-2019 04:23 PM
It seems like simple array operations in a loop.
Go through 2D array element by element replacing each element after you've looked it up in the limit table and use that result with the v table.
I concatenated a 0 element to the front of the index or limit array so that threshold 1-D array rounded down will yield the correct index in the v array.
02-20-2019 04:28 PM
Thank you, there's still tones of function I'm unaware of in Labview.
02-20-2019 04:30 PM - edited 02-20-2019 05:00 PM
I got something similar. Be careful if the matrix can contain negative numbers/thresholds, though. Use -inf as the first element.*
(I probably would use the IPE on the matrix directly, though)
*EDIT: -Inf does not work right. Use a value smaller that the smallest matrix element as first element if the index array. See below.
02-20-2019 04:39 PM - edited 02-20-2019 04:56 PM
@altenbach wrote:
(I probably would use the IPE on the matrix directly, though)
That's how that could look like (same result):
02-20-2019 05:00 PM
Sometimes, operations in arrays are more efficient because of SSE use. You need to do a careful benchmarking to see what's fastest. Here is another alternative.
02-21-2019 11:09 AM
Of course in the most general case, you need to be careful constructing the final "index" array to ensure it is non-descending and such.