LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sorting data in memory

Hello,
 
I have created a system that can read data from a  text file, the data is a list of car brands. i want to know how can i find out the top 5 car brands from the data that i read in from the text file. I have no clue of what feature in labview i should be looking at to do this.
 
thanks
 
Jim
0 Kudos
Message 1 of 4
(2,813 Views)
A list of car brands alone does not give you any indication on popularity. 😉
  1. Is there a second column with sales figures?
  2. Does your list contains multiple occurences of each brand and you want to look for the most frequent?
Both problems are easy to solve. You probably want case #1.
 
Create a 2D array of strings (table) of all your data. slice out the desired column to sort by, convert it to numeric (You don't want to sort numbers aphabetically ;)), and use it to set the sort key(see below). Using the key, generate a sorted table in a loop.
 
To obtain the sort key, it is useful to know that arrays of clusters are sorted primarily by cluster element 0. This makes it easy to generate the sort key as follows.

Most likely, you can generate your sorted table in the second loop directly. If you get stuck, attach your code. Good luck. 🙂
 

Message Edited by altenbach on 02-10-2007 09:06 AM

0 Kudos
Message 2 of 4
(2,805 Views)
I am a bit confused on how to get the top 5 brand based on on the occurance. I understand that the sort 1D array put the data in aphabetical order but from here how do you get the five most popular brands of cars.
 
thanks
Jim
Download All
0 Kudos
Message 3 of 4
(2,795 Views)
OK, it seems you want to list the brands by frequency of occurence. I originally thought you had a table where each brand occurs once, but the popularity is in another column.
 
Easiest it to use a FOR loop and shift register and count successive identical entries in an array sorted by brand. Then we sort again by frequency and only show the top 5.
 
The attached program top5.vi shows one possibility. Please verify correct operation.
 
Since I edited in LabVIEW 8.0, I had to change the file read operation (only 8.20 can read string tables directly). Notice that your file has some extra whitespace, e.g. "DODGE" and "DODGE " occur both. I trim whitespace to make sure they are the same.
 
 
0 Kudos
Message 4 of 4
(2,784 Views)