06-21-2012 03:28 PM
In Mathematica, the command Chop[x, y] returns 0 if |x|<y and x otherwise. In other words, small numbers (assuming y is small) are approximated as 0.
What is the most efficient way to accomplish this in LabVIEW? I need to apply the operation to several large 2D arrays.
Thanks,
Anthony
Solved! Go to Solution.
06-21-2012 03:44 PM
I'm not sure about efficiency and it probably depends on how many elements "large" refers to.
I'd try autoindexing a loop, use In Range along with a Selector to put 0 if In Range, and leave the element unchanged if not.
06-21-2012 03:52 PM
Thanks Taki1999. That's the first thing that came to my mind too - see my similar VI attached below. It works, but I thought surely LabVIEW should have something built-in that would be faster. In my case "large" means something on the order of 1000x1000 (I am working with images).
06-21-2012 04:02 PM - edited 06-21-2012 04:03 PM
This might be a little faster since it's not hitting the terminal on each iteration.
I also think Absolute values tend to be slow mathematical operations.
06-21-2012 04:08 PM
I just did that too. It doesn't seem a whole lot faster when I test it with a big array, but I agree that it should be a little faster. Thanks again for your help!
If anyone has a better solution, I would love to see it.
06-21-2012 04:24 PM
This approach appears to be a little more than twice as fast as the Select approach. I tested it with a 1000x1000 random array of values between 0 and 1, with a threshold of 0.1:
06-21-2012 04:27 PM
06-21-2012 04:31 PM
I was also about to suggest the idea Ben shows - I think that's fastest. Also, if your image is only positive numbers then you don't need to perform the Absolute Value function, which will save some time.
06-21-2012 04:33 PM
You're all very clever! Some of my arrays will have negative values, so I will probably add a case structure to calculate absolute value in those cases.
06-21-2012 04:33 PM
@GregSands wrote:
I was also about to suggest the idea Ben shows - I think that's fastest.
Based on my benchmarks, the methods have the following performance with a 1000x1000 array of values between 0 and 1, with a 0.1 threshold:
Taki9999 - 35 ms
ben64 - 25 ms
Darren - 15 ms
I ran these benchmarks in LabVIEW 2011.