05-08-2021 01:10 AM
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]
Solved! Go to Solution.
05-08-2021 01:14 AM
05-08-2021 12:11 PM
Seems like a trivial problem once we know what you actually want to do. Unfortunately, most of your terms aver very ambiguous.
Does the row order need to be maintained or should it be sorted by the key column?
So. Many. Questions.
05-09-2021 11:39 AM
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.
05-09-2021 12:03 PM
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).
05-09-2021 12:20 PM - edited 05-09-2021 12:44 PM
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.)
05-09-2021 12:44 PM
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.)
05-09-2021 01:05 PM
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?
05-09-2021 01:15 PM - edited 05-09-2021 01:17 PM
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.
05-09-2021 01:22 PM - edited 05-09-2021 01:26 PM
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!