I have made a VI that took as inputs a 2D array and a 1D array.
The 1D array is the first column of the 2D array and it's an angular value.
The second column of the 2D array is the effort value corresponding to the angular value.
I implemented a VI that eliminates from the 2D array all the copies of the same angular value. (see attachments)
The problem is that this algorithm sends as output the first value that is different from the previous one but I want to find from the multiple copies of the same angular values which is the one that has the maximum associated effort value and send that to the output.
The result I want is a 2D array in which each angular value appears only one time and that is the one with maximum associated effort value selected from the multiple copies of the same angular value.
Can someone help me overcome this issue?
Solved! Go to Solution.
One small tip: it's usually a bad idea to do equality comparisons on floating point values due to round-off and truncation errors. It's much better to look for an absolute difference that's less than a small threshold (maybe try 0.001 degree)?
You'll have more work to do on your code than that, but it leaves you with one less problem than you have now.
It is not useful to attach an image labeled "data". A better way is to run your VI until all controls contain data, then make the current values default. Save under a new name and attach it again.
Where does the data come from? It is is directly converted from measured values at a lower bit count, equal comparison might be OK, (but still somewhat dangerous). You angles seem to be quantized to multiples of 0.09 degrees (exactly 4000 steps/full rotation!). You could use that to convert to integers for safer equal comparison. Maybe a more robust data handling would be to average all values for the same angle. Can we assume that all equal angles are adjacent to each other or will they e.g. repeat after one turn?
You can wire [i] directly to the case structure and make one case "0" and the other "default".
Think about using conditional tunnels.
Since you have LabVIEW 2019, you can use a map as follows:
(This will work even if equal angles are not adjacent to each other. Warnings of using DBls for the angle still apply. Maybe you can convert it to integer steps. I don't think there is a need for the separate angle array. Seems redundant.)
The code below will return the output sorted by angle, i.e. reversed to what you get because your angles are negative. It is not clear if that's OK, but would be easy to change.
Thanks to everyone for the tips.
Special thanks to Altenbach, your solution was exactly what I was looking for!
I never used maps but they are really useful to manipulate pairs of values.
Keep up the good work!