08-06-2019 12:57 PM
I have an initialized 10,000 1D array with values -1. After replacing some values with collected data, I loop through the array, removing places where -1 still exists. However, it converts my data into integers where it initially had 2 decimal places. Any way around this?
Solved! Go to Solution.
08-06-2019 01:03 PM
The selection terminal of a case structure defaults as a numeric input to I32, that's why the output of this terminal is an integer value.
Use another tunnel through the case structure border, then the value will remain double.
08-06-2019 01:06 PM
@pvally wrote:
However, it converts my data into integers where it initially had 2 decimal places. Any way around this?
That is because a case structure cannot accept a floating point value. It converts it to an integer first. From what I am currently seeing, it looks like you should be using I32 for everything anyways. But I am also VERY confused about what the code you shared is trying to do. Could you share some more about what your code is supposed to be doing? Maybe a little more context (code before and after the snippet) would help as well.
08-06-2019 01:11 PM
Can you demonstrate what you mean in this test VI.
08-06-2019 01:14 PM
An array is leading into the for loop; it contains decimal values (ex: [298.17, 298.85, ... , -1, -1 ...]). It then returns an array containing [298, 299, ... ], removing the -1 places.
08-06-2019 01:38 PM - edited 08-06-2019 01:39 PM
If using the case structure method to delete elements from the array only works for integers, can you recommend another way I delete the extra values from the array while maintaining the decimal places?
08-06-2019 02:42 PM
08-06-2019 02:47 PM - edited 08-06-2019 02:48 PM
@pvally wrote:
If using the case structure method to delete elements from the array only works for integers, can you recommend another way I delete the extra values from the array while maintaining the decimal places?
The problem was not with removing the values. The problem was that you were replacing values in your array with integer values. As noted previously based on the limited code shown in the picture it is possible that by using the actual array index value your code would probably work.
I've attached a quick vi with an alternative method. The FOR loop on the right should do what you want. It takes an array that contains values of -1 or numbers greater than or equal to 0 and removes all of the values that are -1. If you have negative numbers then you need an entirely different approach.
Edited to add: Looks like GerdW already supplied the same solution.