complexe Minimum-computation



  • Hallo,

    I have to find a minimum in last 8 stored values in matrix actmin_all[8][256].
    Is this correct, and can it be simpler realised:
    for(j = 0; j < 7; j++)
    {
    for(i=0; i<256; i++)
    {
    if(actmin_all[j][i] < actmin_all[j+1][i])
    { actmin_all[j+1][i] = actmin_all[j][i]; }
    }
    }
    Is the same way to compute a maximum? In matlab there are the functions like:
    min(actmin_all), which gives the vector with minimum values; is there something like that in C++?
    Thank you for any help or advice... 🙂

    Greets,
    Emir



  • It should be
    [cpp]for(j = 0; j < 8; j++) [/cpp]

    Please use Codetags next time.
    Wrong Forum, has nothing to do with MFC.
    Moved ➡



  • I'm not sure what exactly you want to do with your code ... Sort your array? Or just get the smallest value in it?



  • I want just to get a min. values. On the way I wrote, the min. values are actually stored in last row... However I hope there is simpler way to do it...

    Greets,
    Emir.



  • std::vector from the includefile vector with the function sort from the includefile algorithm?

    btw: of what type is your matrix? int?



  • My matrix is double...
    I need for example from matrix
    2 2 2 2 2
    3 3 3 3 3
    1 2 1 2 1
    4 5 4 2 4

    Vektor with min. value:
    1 2 1 2 1

    My algorithm, that is with 2 for loops realised, do that (and it is realy 7, and not 8, like you wrote -> see the alg. exactly). I think it can and should be easier realised...



  • Off the top of my head & untested:

    #include <algorithm>
    
    typedef int Row[8];
    
    bool rowLessThanRow(const Row& first, const Row& second)
    {
        return first < second; // Pseudocode, put your comparison logic here
    }
    
    ...
    
    Row rows[256];
    Row* min_row = std::min_element(rows, rows + 256, rowLessThanRow);
    // *min_row is the "smallest" row
    


  • #include <algorithm>

    wird das auch vom ti-compiler übersetzt, denn ich glaube, dass dieses include
    zur stl (standard template library gehört ... und die wird am dsp nicht rennen - schätze ich, gibt es noch was anderes!)

    Danke für die Hilfe...

    LG



  • Das erste mal, das ich mit ner "freestanding Implementaion" zu tun habe. <algorithm> ist teil der STL, wird also nicht gehen.

    Aber du kannst genau deinen Algorithmus nur mit nem größer als (>) verwenden, um das Maximum zu bestimmen.

    Und es muss 8 heißen und nicht 7, falls die Information, dass es um 8 Zeilen geht richtig ist. Oder du schreibst <= 7, was aber eher unüblich ist.


Anmelden zum Antworten