Finding the most common value in an array of enums

Hello,
I'm looking for an elegant way of finding the most common value in an array of enums
My enum being:
0 - Close
1 - Open
2 - Undefined
For instance, if my array contains:
Close, Close, Open, Close, Close, Open.
The most common value would be "Close"
I have created a very customized VI that allows me to obtain the desired result, but I'm really not proud of doing it this way, simply because I would have to modify it if I were to add a new value to my enum...
If someone can share some ideas to enlighten me, I would REALLY appreciate it.
Thanks in advance!
Jorge
Solved!
Go to Solution.

Here is the variant using the search method. This method will run N-1 times where N is the number of ENUM elements. Yes, it is a bit more complex than the brute force method but it would execute fairly quickly. The sort would probably be the time consuming task.
Mark Yedinak
"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Attachments:
ENUM Counter.vi ‏14 KB
Enum.ctl ‏4 KB

Similar Messages

  • How would I find the most common value every nth row in a column

    SCENARIO 1
    I have a column with a series of numbers in c1:c1000 as follows:
    2
    2
    3
    1
    1
    4
    2
    3
    1
    2...
    and I would like to find the most common value for every nth (in this case, second) row.
    SCENARIO 2
    Originally, I created a separate column in J and used this to find a value of 0 or 1 via a filter to label the rows odd or even. I was then going to create two separate columns, one for even rows of data and another for odd rows of data to separate them and perform functions on each column. But I do not know how to copy just the filtered data to one of the new columns to apply the MODE function (or any other for that matter).
    Perhaps my question should be: after applying a filter, how do i copy just the visible filtered data of every nth row to a new column in my spreadsheet while retaining the original column with all rows of data? 
    BACK TO SCENARIO 1
    If I do not need to go through this effort, I would just apply the MODE function (or AVERAGE or SUM) to every nth row in the original data column.

    Since Index and Offset were already taken, I used INDIRECT(ADDRESS()) in my example.
    Here's how I approached it:
    Expressions are as follows...
    Data Subset, Column A, Row 2: =IF(StartingRow :: A, 1, NSelector :: $A)
    Subsequent rows in Column A: =IF(ROW()<COUNT(Input :: $B)/NSelector :: A:$A+2, A2+NSelector :: $A, "")
    Data Subset, Column B, Rows 3
    throuth the last: =IFERROR(INDIRECT(ADDRESS(A+1, 2, ,,"Input")), "")
    Stats, Column A, Row 2: =IFERROR(MODE(Data Subset :: B), "No Mode")
    Stats, Column B, Row 2: =COUNTIF(Data Subset :: B, A)
    Lots of ways to skin this cat.
    Jerry

  • How to find the most matched values in the set of map?

    Hi friends!
    I have two vectors
    vector<int> V1; vector<int> V2;
    and a map<int, set<int>> M1;
    I want to select common values from both V1 and V2 and check those values with the set in the map M1.
    For example:
    V1 contains;
    2  4  6  8  9
    V2 contains;
    4  5  6  9  10 
    M1 contains;
    1=>1  2  5  9
    2=>4
    3=>5   10
    4=>2  4  8
    5=>4   9
    6=>4   6
    7=>9  12
    When we select the common values of V1 and V2 it is 4, 6, 9.
    And we search for all 4, 6, 9 from the values of M1 which give more appropriate.
    But, no all values in the set of map.
    Then, we delete any value from 4, 6, 9, then remaining values would match any values from the map.
    From the example, if we delete 6, then remaining 4, 9 will match with 5=>4  9, or if we delete 9, then 6=>4   6. Any one of the keys can be selected.
    I know how to select the common values from V1 and V2, but I do not know how to match with the values and select the appropriate key from M1.
    Could anyone help me to solve this?

    This is not the question you asked, except perhaps in the subject. The subject is not the right place to put key features of the question. It is also important to use the body to ask just the question you want
    answered. For example your real question has nothing to do with V1 and V2, just the common vector V (e.g. 4 6 9).
    One way to solve your problem would be to create a new map
    map<int, set<int>> M2;
    with the same keys as M1. Each set of M2 should contain the elements of V that are
    not in the corresponding set of M1.
    Then pick the key of M2 that has the smallest set. If that set is empty, then the whole of V can be used. Otherwise the smallest set tells which elements of V have to be removed, and which is the desired key of M1.
    In your example, key 5 of M2 will contain just 6, so you should remove 6 from V and select key 5.
    Yes fine. I tried the following code and it creates the map M2 (NewMyMap in my code). But how to find the smallest set starting from size 1?
    #include <vector>
    #include <algorithm>
    #include <iostream>
    #include <map>
    #include <set>
    using namespace std;
    typedef vector<int> IntVec;
    typedef set<int> IntSet;
    typedef map<int, IntSet> SetMap;
    bool IsValueNotInSet(int value, IntSet& S);
    SetMap CreatNewSetMap();
    IntVec IVec; //This vector is for selecting certain keys from mySet map.
    IntVec myVec;
    SetMap mySet;
    SetMap NewMyMap;
    int main()
    IVec.push_back(3); IVec.push_back(4); IVec.push_back(5); IVec.push_back(6);
    myVec.push_back(4); myVec.push_back(6); myVec.push_back(9);
    IntSet tempS;
    tempS.insert(1); tempS.insert(2); tempS.insert(5); tempS.insert(9);
    mySet.insert(make_pair(1,tempS));
    tempS.clear();
    tempS.insert(4);
    mySet.insert(make_pair(2,tempS));
    tempS.clear();
    tempS.insert(5); tempS.insert(10);
    mySet.insert(make_pair(3,tempS));
    tempS.clear();
    tempS.insert(2); tempS.insert(4); tempS.insert(8);
    mySet.insert(make_pair(4,tempS));
    tempS.clear();
    tempS.insert(4); tempS.insert(9);
    mySet.insert(make_pair(5,tempS));
    tempS.clear();
    tempS.insert(4); tempS.insert(6);
    mySet.insert(make_pair(6,tempS));
    tempS.clear();
    tempS.insert(9); tempS.insert(12);
    mySet.insert(make_pair(7,tempS));
    cout<<"MYVEC\n";
    cout<<"-------------\n";
    for(IntVec::iterator itv = myVec.begin(); itv != myVec.end(); ++itv)
    cout<<(*itv)<<" ";
    cout<<"\n\n";
    cout<<"\nMYSET\n";
    cout<<"-------------";
    for(map<int,set<int>>::iterator its = mySet.begin(); its != mySet.end(); ++its)
    cout << endl << its->first <<" =>";
    for(IntSet::iterator sit=its->second.begin();sit!=its->second.end();++sit)
    cout<<" "<<(*sit);
    cout<<"\n\n";
    NewMyMap= CreatNewSetMap();
    cout<<"\nNEWMYSET\n";
    cout<<"-------------";
    for(map<int,set<int>>::iterator its1 = NewMyMap.begin(); its1 != NewMyMap.end(); ++its1)
    cout << endl << its1->first <<" =>";
    for(IntSet::iterator sit=its1->second.begin();sit!=its1->second.end();++sit)
    cout<<" "<<(*sit);
    cout<<"\n\n";
    return 0;
    bool IsValueNotInSet(int value, IntSet& S)
    IntSet::iterator it=find (S.begin(), S.end(), value);
    if (it!=S.end())
    return false;
    return true;
    SetMap CreatNewSetMap()
    IntSet TSet;
    for(IntVec::iterator it = IVec.begin(); it != IVec.end(); ++it)
    SetMap::iterator its = mySet.find(*it);
    if (its != mySet.end())
    TSet.clear();
    int key = its->first;
    IntSet& itset = its->second;
    for(IntVec::iterator itv = myVec.begin(); itv != myVec.end(); ++itv)
    if(IsValueNotInSet((*itv), itset))
    TSet.insert(*itv);
    NewMyMap.insert(make_pair(key,TSet));
    return NewMyMap;

  • How to find make most common value?

    Hello,
    I have data like this
    Customer Invoice number payment term
    ABC 10001 K20
    ABC 10002 K40
    ABC 10003 K20
    ZYX 10004 K30
    ZYX 10005 K20
    ZYX 10006 K30
    Now I want to make report which will show most common payment term. I tried with count etc. with no result.
    I want report like this
    ABC K20
    ZYX K30
    Regards,
    Luko

    Hi,
    You can set the GROUP BY clause in the Advanced Tab
    http://gerardnico.com/wiki/dat/obiee/group_by
    Please refer the below links,
    Group By in OBIEE
    Or,
    count(customet by customer,payment term) (or) you can apply those columns in Advanced tab then apply below filter in your report.
    Apply fiter >grather than 1
    Hope this help's
    Thanks,
    Satya

  • Find the 20 max values

    Say i have an array of 40 doubles. How can i find the 20 maximum values from my array?

    Do you know how to sort?
    Can you use the Java APIs?ha ha..
    yeah.. sort the array and pick the 20.
    Or if you write something like a bubble sort, let the outer loop executing half times as the usual..

  • Where can i find the most popular common effects and title template for free online?

    where can i find the most popular common effects and title template for free online?

    Hello,
    I have a couple of links that I have used:
    http://www.solarisinternals.com/wiki/index.php/ZFS_Best_Practices_Guide
    http://www.solarisinternals.com/wiki/index.php/ZFS_for_Databases
    These are not exactly new, so you may have encountered them already.
    List of ZFS blogs follows:
    http://www.opensolaris.org/os/community/zfs/blogs/
    Again, there does not seem to be huge activity on the blogs featured there.
    jason.
    http://jarneil.wordpress.com

  • Finding the 25th largest number in an array

    How would I say find the 25th largest number in an array?
    Or nth largest number?
    Chris

    I find most of these answers correct, but without previous knowledge of the size of the array, I would do things differently.
    In the enclosed VI, a cluster is formed of all array values and their index. When the array is then sorted, the first cluster element is used as the first sort criterium, then the second cluster element. This allows a single array operation (Sorting) to take care of any searching, whilst the cluster retains the index of the original array.
    Coupling this method with an unitialised shift register, you can also cache the sorted array to allow for more rapid processing if you require more than a single indexed value.
    Another way to achieve this is (Assuming you`re seeking the 25 largest) to simply get the max and min at t
    he very beginning, feed the array into a loop with a shift register, set the value at the index returned for max each run to the initial min value -1, and repeat another 24 times.
    Regarding memory use and execution speed, I`m not sure if searching an array 25 times is quicker than a single sort or not (No new array is created), but both versions are viable.
    Shane.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
    Attachments:
    Get_Nth_largest-smallest_(6.1).vi ‏31 KB
    Get_Nth_largest-smallest_(6.1)_-_version_2.vi ‏42 KB

  • In your experience what are the most common errors in binding files when deploying?

    As the title suggest I'm interested in discussing the most common errors in binding files when deploying.
    Reason for this is that I'm currently working on a Powershell script that can parse a binding file and create a reader friendly report (rtf format) with various information.
    But the main purpose for this script is to find common errors in the binding file used. And so far these are the ones I've thought of:
    - Tracking enabled for either services or the pipelines they are using (if it's a binding meant for Prod).
    - Orchestrations logical ports not having any ports bound to them.
    - URI containing certain words that's not ok. For example if a binding meant for Prod contains the word "test" anywhere in the URI then that should be reported in the created rtf report. This also applies vice versa.
    So now I need your help with coming up with more ideas on common errors that need to be looked after and reported on if found! 
    Additional features the report should contain:
    - Listing the details of each orchestration, send port, receive port along with their associated receive location(s). To better understand and get a quick overview on exactly what settings are planned to be deployed. Especially the "TransportTypeData"
    section which otherwise can be quite tedious to read.
    - List each unique host instance, so that I can easier see directly which ones might need a restart after an import.
    I'd appreciate if you can come up with any more features that should be included in this script.
    /Christian @ IntegrationAdmin.com

    Filter on send port not on the same line as the Filter tag.
    This one is a nice one, I ran into it several times. Mostly after copy/paste of a port definition for a binding file, because Visual Studio is formatting after paste the XML in a way the filter will get invalid. This leads to a cryptic error
    during importing the binding.
    http://winterdom.com/2008/06/biztalkfiltersnotgettingimported
    Jean-Paul Smit | Didago IT Consultancy
    Blog |
    Twitter | LinkedIn
    MCTS BizTalk 2006/2010 + Certified SOA Architect
    Please indicate "Mark as Answer" if this post has answered the question.

  • What are the most common questions in the forums?

    I have my own ideas about what are the questions we see asked over and over and over again in here. Everyone post your ideas here so we can compile a FAQ and maybe post it somewhere (Virum, your new site? :) )

    Please do my homework/coursework/think for me
    This has to be by far the most common type of question asked on the forums.
    Classpath questions
    HashCode questions
    Pointer vs Reference Debate (totally spurious but people spew 100's of pages arguing about something that is perfectly obvious)
    A very good Thread that is probably 1000's of entries long by now is the
    "How to get your questions answered promptly" one (or however this is called). A recap of that published somewhere would be of tremendous value, especially if it was presented as a page you had to go through before landing in the forums to post your latest "Java Challenge" aka "do my coursework" on the boards.

  • Find the most recent file

    greetings,
    I am developing a web site in which we need to extract the 1st paragraph of the most recent press release and post it as content in a separate page. The press releases are all in their own separate files that get dynamically included into a templates page.
    I am able to open the file, get the text, set it to a variable and post to the separate page without a problem. What I need to know is how to know which file to open and read.
    I can use the lastModified() method to compare one file agains another, which I suppose would work fine it it was only a handful of files I Was comparing, but this could potentially be a pretty large number of files.
    Can anyone think of a relatively efficient way to do this? Are there any array sorting methods that may help here?
    Thanks,
    -d

    If you're looking to sort your File array by lastModified() date, then use the Arrays.sort() method with the following header...
    Arrays.sort(Object[] a, Comparator c)
    You can easily define the Comparator to sort by the date (either ascending or descending) and voila, you can quickly and easily find the most recent.

  • How can if find the most repeated character and number ???

    Hi,
    I have a question. For instance, if we have a text file which contains:
    aaabbbhhhhhhtttttsjs12366
    How can i find the most repeated character and number. I have to add this code to the following program:
    I will aprreciate if you can help.
    Regards,
    Serkan
    import java.io.*;
    public class LineLen {
         public static void main(String args[]) throws Throwable {
              final String filename = "deneme1.txt";
              BufferedReader infile = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
              String line = infile.readLine();
              int linenum = 0;
              while (line != null) {
                   int len = line.length();
                   linenum++;
                   System.out.print(linenum + "\t");
                   for (int i = 0; i<len; i++)
                   System.out.print("*");
                   System.out.println("");
                   line = infile.readLine();
    }

    For a small alphabet like English, array migt be used:
    //in a for loop
    ++array[s.charAt(i)];For a big alphabet like chinese, HashMap might be barely used:
    map.put(s.charAt(i), increment(map.get(s.charAt(i))));
    // increment is a user defined method, possibly for an Integer object,
    // that returns a new Integer object

  • How can we find the most usage and lowest usage of table in Sql Server by T-SQL

    how can we find the most usage and lowest usage of table in Sql Server by T-SQL
    The table has time stamp column
    StartedOn datetime
    EndedOn datetime

    The Below query has been used , but the textdata column doesnot include the name of the table ServiceLog.
    SELECT
    FROM
    databasename,
    duration
    fn_trace_gettable('F:\Program
    Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\log_148.trc',
    default)
    WHERE
    DATABASENAME='ZTCFUTURE'
    AND TEXTDATA
    IS
    NOT
    NULL
    --AND TEXTDATA LIKE 'SERVICE%'
    order
    by cpu
    desc; 

  • Creating a view on two ODS using the most actual value of Timestamp

    Hi All,
    I am creating a view on two ODS. I have made an internal join of the field timestamp from both the tables. But the timestamp in bot ODS do not match, which is why there is no data visible in the view.
    There is a requirement that the value of timestamp to be used has to be the most actual value of timestamp from the two ODS.
    I would be grateful if some pointers regarding the same could be provided.
    Thanks and regards,
    Shruti Kulkarni

    Hi Shruti,
    ODS should not be linked on Timestamp basis, there must be some other alternatives like document number, date etc etc...
    In other case if its possible to include addtional key figure in to ODS then
    create a dummy key figure , in the aggregation tab page Select Exception aggregate as "Last Value" and in the "agg.ref char" Select time stamp as info object. This setting will make sure that in the ODS you have only last updated data.
    Hope that helps.
    Regards
    Mr Kapadia
    Assigning points is the way to say thanks in SDN.

  • Preview failed because Adobe Muse could not make a connection over HTTP. The most common cause of this is Firewall software which prevents HTTP connections. You may need to change Firewall settings to allow Adobe Muse to make connections.

    Preview failed because Adobe Muse could not make a connection over HTTP. The most common cause of this is Firewall software which prevents HTTP connections. You may need to change Firewall settings to allow Adobe Muse to make connections.
    no firewall at all, in win 8.1, turned it off for all networks
    ftp and publish works just fine

    Hi,
    Please take a look at this post : Re: Adobe Muse - Preview Failed
    Regards,
    Aish

  • Application Tuning to find the most expensive sqls

    I have a schema in oracel 9i Release 2 and I want to do a performance testing from application side. Application is developed in Java . There are many queries in java side and some stored procedures are called while running the application.
    So I need to find the most expensive sqls by running the application and tracing the top sqls
    If I set trace enable at database level the trace files will be generated for all the connected sessions right? I want the trace file for only one schema. If I enable trace for a session I will not be able to trap the sqls since the application runs from another session . connection pooling also is used. suggest some good approaches to capture the most expensive sqls?

    Does the answers in your application tuning not suitable for you ?
    Nicolas.

Maybe you are looking for