Menu

#2539 Matrix and pseudocolumns

None
closed-not-a-bug
nobody
2022-08-16
2022-08-12
theozh
No

In a matrix you have row- and column-indices.
I expected to be able to use these indices like in normal tabular data via the pseudocolumns.

column(-1) seems to be the row index
column(1) seems to be the nonuniform x-values
column(2) seems to be the nonuniform y-values
column(3) seems to be the z-values

Consequently, I hoped that column(0) is the column index,
but apparently it seems to be int(column(3)).

Am I getting something wrong here?
Tested with gnuplot 5.0.0 and 5.4.1

Script:

### column indices in matrix

$Data <<EOD
 X   1      3      7
 0   11.1   21.2   31.3
 2   12.1   22.2   32.3
 5   13.1   23.2   33.3
 9   14.1   24.2   34.3
EOD

set table $Test
    plot $Data nonuniform matrix u -2:-1:0:1:2:3 w table
unset table

print $Test
### end of script

Result:

 0       0       11      1       0       11.1
 0       0       21      3       0       21.2
 0       0       31      7       0       31.3
 0       1       12      1       2       12.1
 0       1       22      3       2       22.2
 0       1       32      7       2       32.3
 0       2       13      1       5       13.1
 0       2       23      3       5       23.2
 0       2       33      7       5       33.3
 0       3       14      1       9       14.1
 0       3       24      3       9       24.2
 0       3       34      7       9       34.3

Discussion

  • theozh

    theozh - 2022-08-12

    Just in case, there is a workaround:

    Script:

    ### column indices in matrix, gnuplog-workaround
    
    $Data <<EOD
     X   1      3      7
     0   11.1   21.2   31.3
     2   12.1   22.2   32.3
     5   13.1   23.2   33.3
     9   14.1   24.2   34.3
    EOD
    
    colIdxFix(n) = (r0=r1,r1=column(-1),r0==r1?c=c+1:c=1)
    
    set table $Test
        plot r1=c=0 $Data nonuniform matrix u -2:-1:0:1:2:3:(colIdxFix(0)) w table
    unset table
    
    print $Test
    ### end of script
    

    Result:

     0       0       11      1       0       11.1    1
     0       0       21      3       0       21.2    2
     0       0       31      7       0       31.3    3
     0       1       12      1       2       12.1    1
     0       1       22      3       2       22.2    2
     0       1       32      7       2       32.3    3
     0       2       13      1       5       13.1    1
     0       2       23      3       5       23.2    2
     0       2       33      7       5       33.3    3
     0       3       14      1       9       14.1    1
     0       3       24      3       9       24.2    2
     0       3       34      7       9       34.3    3
    
     
  • theozh

    theozh - 2022-08-14
    • labels: --> matrix, pseudocolumns
    • Group: -->
    • Priority: -->
     
  • Ethan Merritt

    Ethan Merritt - 2022-08-15

    The pseudocolumns are defined in terms of lines in an input file. Whenever a line of input is read, the values of the pseudocolumns are updated accordingly. Since a row of matrix data is all on one line, the line counter column(-1) is updated on each row of data and can be used as a row number.

    But incrementing or resetting each pseudocolumn when a new line is input means that every datum on that line corresponds the same current values of the pseudocolumns. There is no provision for reporting what you are looking for (implicit column position within a matrix). As currently implemented, when you ask for any pseudocolumn you are essentially asking "what was the value of this counter when this line was read in?" The answer will be the same for all data points read at that time.

    I see that someone added a line in datafile.c that is effectively
    if (df_matrix_file) df_datum = df_column[i].datum;
    which is the code that produces you see in your test script, since column(0) reports df_datum. I do not know what the intent was there, but I think it probably had to do with binary matrix data rather than ascii non-uniform matrices.

    A new pseudocolumn or some other function that caclulates column position could be a feature request.

     

    Last edit: Ethan Merritt 2022-08-15
  • theozh

    theozh - 2022-08-16

    Thank you Ethan for checking. Ok, so, it's not a bug, maybe a feature. I see, I didn't think of binary matrix. It seems to be there at least in gnuplot 4.6, maybe "since ever". Then there probably was some intention behind it.

    So, I will file a feature request. And this case can be closed.

     
  • Ethan Merritt

    Ethan Merritt - 2022-08-16
    • status: open --> closed-not-a-bug
     

Log in to post a comment.