03-13-2015 09:11 AM
I have a 1D array of data which varies betwen positive and negative values. I am trying to search it for negative values and remove them from the array. This corresponds to column data in the second 2D array which also needs to be removed. One minor issue is that there is one extra column in the 2D array which has to be skipped over. I have code which should do this. The problem is that if I have two negative numbers in a row the code doesn't thow out the second one.
This first picutre is the answer I get when positive and negative values alternate. It is displaying the correct answer.
When I change the first1 from positive to a -1 as shown below...
... I get the following answer.
FYI some of the other things such as the conversion are there because the actual data set I am trying to manipulate is huge. I am testing everything I do with numbers I can actually track before I implement it in my actual program. That is why I am doing some extra things.
Thanks for the help!
Solved! Go to Solution.
03-13-2015 09:35 AM
Your problem is that you are using the "i" in the loop. "i" is not in sync with your array when deleting something in it.
03-13-2015 09:44 AM
Here's the solution, only increase the index when you don't delete an element. In addition you were using the "less then or equal" when you should use the "less than".
03-13-2015 09:45 AM
Also, you are taking i+1 for your 2D array, but only i for your 1-D array. So you are not even working on the same index of the array like you thing you are.
I see you have LabVIEW 2011. I don't think that version had conditional tunnels yet. If it does, then that is the easiest way to code this.
If not, you will need to maintain your own count within a shift register instead of using i. If you need to delete something, then just past the i through, (because everything later in the array will move up). If you don't, then add 1 to the counter and put that back into the shift register.
Also consider working from the end of the array and move to the front. Then your index of interest will be Array Length - 1 - the current i value. Because you will have already worked through the later elements of the array, you won't care that they move up as you delete items from the array.
03-13-2015 09:49 AM
Thanks for the help everyone. I figured it was something simple that I was just overlooking.
03-13-2015 10:09 AM
I like using the build array function, when I am trying to eliminate an element from a current array. Something like this (I only used the string example)
03-13-2015 12:19 PM
Use auto indexing on the input and conditional indexing on the output.
Can't get much simplier.
Your 2D array has more cols than your 1D string array. What are your rules for when that happens
Delete the extra cols?
Pad your 1D string array with extra elements to match the number of cols of your 2D array?