08-21-2010 06:47 PM
Hi, I'd like to search a column in a 2D array for values that meet a certain criteria (e.g. < 0.98). Based on which rows meet this criteria, I want to replace the values in a different column of the array (change to 'NaN' so that the values will not be included in any calculations on that column, for example the finding the mean). I've attached a sample .csv file. If the values in column 3 (index 2) are less than 0.980 (or some other user defined value), then the value in column 2 (index 1) should be replaced with NaN. Can someone help out with this search and replace task?
Thanks,
Keith
(using LV 2009 SP1)
Solved! Go to Solution.
08-21-2010 07:02 PM
You should just loop through your array. Look at the array row by row and make the replacements as necessary. Keep the array in a shift register.
08-21-2010 10:58 PM
Ah, of course! By rows. Thanks, that's what I needed to get over my brain lock. I was stuck thinking in terms of columns and thought I would have to deal with the two number columns as separate 1D arrays. Here's what I came up with. The first column of Date/Time is split off to convert into a time stamp. Any suggestions for improvements are welcome.
08-21-2010 11:30 PM - edited 08-21-2010 11:32 PM
Some quick hits.
You can merge the two For Loops together
You don't need the constants 1 and 2 in the index array. They will be set automatically when you expand down the index array once you've wired in the 0 into the column index.
It seems like a lot of extra array manipulation going on unnecessarily.
See below. I didn't try to duplicate your code to see how it actually runs, but I believe what I've attached will yield the same result with a lot fewer steps.
08-22-2010 02:02 AM
Thanks. that's a lot cleaner