LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting out 2D array by condition

Solved!
Go to solution

Hi all,
I got a csv file containing 2 columns of data (and many rows). One of the columns contains some unnecessary details, so I need to extract the relevant rows only for my application.
I created a new 1D array containing all the necessary info, but now I have difficulty to sort the original 2D array by those values. Its important to notify that each row in this table is dependent on one another and I don't know how to leave only those necessary rows.
Your help will be greatly appreciated. 
[using LabVIEW 2018]

0 Kudos
Message 1 of 16
(249 Views)

What about providing a simplified example of your data, with giving the expected filtered output?

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 2 of 16
(241 Views)

Seems like a trivial problem once we know what you actually want to do. Unfortunately, most of your terms aver very ambiguous.

 

  • What is "unnecessary details? (Certain values, Certain range(s)? Duplicate values? etc.)
  • What is "extract"? (remove or keep?)
  • What is "necessary info"? (Set of valid values of the key column? Set of indices for rows to keep?)

 

Does the row order need to be maintained or should it be sorted by the key column?

 

So. Many. Questions.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 3 of 16
(178 Views)

Hi, 
I attached the data I calculated,
I want to remove duplicate values, values not in specific range in the frequency column and by that remove it gain values.

I didn't understand what you meant with key column. I am new to LabVIEW, so if there is some way to belong some value to other, it will help me a lot.

Thanks in advance.

0 Kudos
Message 4 of 16
(157 Views)

The key column is apparently the frequency. This is the column where we check for duplicate values while we don't care if there are duplicate values in the second column.

 

What should happen if there are duplicated values? (keep only the first? Keep only the last? Average all values of the second row having the same frequency? etc.) 

 

What is your LabVIEW version? The solution will be especially simple if you have 2019 or newer, because you can use maps. But even without maps, this is a trivial problem once we know exactly what you want. (see bold questions above).


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 5 of 16
(152 Views)

Here's how you would keep only the first encounter of each frequency value.

 

(it also removes the header row. For simplicity we assume that zero is not a valid frequency, else some simple changes would need to be made. We also assume that duplicate frequencies are in adjacent rows.)

 

 

altenbach_0-1620580732983.png

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 6 of 16
(146 Views)

Here's how you could average all values from the second column for each unique frequency (using maps this time).

 

(Note that this is more rigorous, because duplicate frequencies don't even need to be adjacent. The output will automatically be sorted by frequency.)

 

altenbach_0-1620582140659.png

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 7 of 16
(140 Views)

Thanks a lot!
Another minor question thought.. if I have 2 arrays with the same type of info. How can I sort them and leave only values that appear in both?
Say I have 2 files with columns for frequency and amplitude and I want to leave only frequencies that shown in both with their amplitudes summed up?

0 Kudos
Message 8 of 16
(134 Views)

I thought the files are already sorted (by frequency. I recommend to use  more precise wording.)

 

Create a map of file #1, then create a new map (map 2) using file #2 and only accept values that also exist in map 1 and combine these with the map 1 values. At the end do the averaging.

 

See how far you get.

 

EDIT: Ah sorry. You said you are using LabVIEW 2018, so maps are out. Too bad! Still, should not be difficult to implement using legacy code.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 9 of 16
(128 Views)
Solution
Accepted by topic author tomershtein

Could it be that your frequencies are originally not really duplicates, but that the first column was accidentally saved with insufficient digits? Maybe you could restore the full frequency range by linear fitting, for example. except for the first point, the frequencies are very linear!

 

altenbach_0-1620584746950.png

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 10 of 16
(123 Views)