LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to replace value in one array column based on value in second column?

Solved!
Go to solution

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)

0 Kudos
Message 1 of 5
(3,475 Views)

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.

Message 2 of 5
(3,469 Views)

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.

 

22074iA325147D5665DC2F

0 Kudos
Message 3 of 5
(3,457 Views)
Solution
Accepted by HawaiiKeith

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.

 

Message 4 of 5
(3,449 Views)

Thanks.  that's a lot cleaner

0 Kudos
Message 5 of 5
(3,435 Views)