Menu

#544 pseudocolumn 0 in a nonuniform matrix

None
closed-accepted
nobody
5
2023-03-16
2022-08-16
theozh
No

Actually, this feature request originates from here: https://sourceforge.net/p/gnuplot/bugs/2539/

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

Why would anyone need the integer values of the matrix values in column(0)?

The wish would be to assign the column index of a nonuniform to column(0), unless it might interfere with or mess up some current or legacy binary matrix functions.

Maybe a change might as well affect the use of every ::startLine:startBlock:endLine:endBlock together with a uniform (or nonuniform) matrix?

Discussion

  • Ethan Merritt

    Ethan Merritt - 2022-08-18

    Here you go:

    commit a5fbd87e14a386c27d07f7552637ca1454818443 (HEAD -> master)
    commit 30b2cd70dbe542f0f3db0849895c80c845cc497f (HEAD -> branch-5-4-stable)
    Author: Ethan A Merritt <merritt@u.washington.edu>
    Date:   Thu Aug 18 11:31:39 2022 -0700
    
        nonuniform matrix input data: column(0) now returns the linear ordering
    
        I.e. for element A[i,j] in an MxN input matrix A
                column(0) / M  gives the row index i
                column(0) % M  gives the column index j
    
        Note that one way of obtaining M and N programatically is
                stats 'matrix.dat' {binary} nonuniform matrix name "A"
                M = A_size_x
                N = A_size_y
    
     

    Last edit: Ethan Merritt 2022-08-18
  • Ethan Merritt

    Ethan Merritt - 2022-08-18
    • status: open --> pending-accepted
    • Group: -->
     
  • theozh

    theozh - 2022-08-19

    Thank you very much!
    Actually, I hoped to directly have the column index in column(0). As you write, now I have to always determine M first, which is (to my opinion) an avoidable extra step (for the user in the script). Why should I be interested in linear order numbers of values in a matrix (unlike in tabular data)? I would say only row and column index are of importance and you can calculate the linear order if (at all) needed. column(0)/M would be redundant, because I have the row-index already in column(-1).

    Although, I have to admit I don't know what is going on "behind the scenes" in the source code, maybe the linear values are easier for programming? I assume gnuplot is reading data line by line and hence doesn't know M at that time. gnuplot would have to determine M first (in an extra step, which I don't have to care as user). Well, now it is analog to tabular data where column(0) is the linear ordered row-index. Anyway, for sure it is an improvement. Thank you again!

     
  • theozh

    theozh - 2022-09-07

    Sorry, again... for curiosity:

    Currently, in both matrices (uniform and nonuniform), column(0) is the "useless" integer of column(3).
    So, instead (to my opinion) the column index could/should be put there.

    Then for a uniform matrix column(2) == column(-1) and column(1) == column(0). This would be redundant but doesn't hurt.

    For a uniform matrix the following script

    ### column indices in uniform matrix
    
    $Data <<EOD
    11.1   21.2   31.3
    12.1   22.2   32.3
    13.1   23.2   33.3
    14.1   24.2   34.3
    EOD
    
    set table $Test
        plot $Data matrix u -2:-1:0:1:2:3 w table
    unset table
    
    print $Test
    ### end of script
    

    returns:

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

    So, "technically" it seems to be possible to put the column index into column(1), so why not into column(0) for both matrix types?

    For a nonuniform matrix_, column(1) and column(2) already contain the nonuniform x- and y-values, respectively.
    If column(0) is the column index, you could easily (without extra steps) plot a (nonuniform) matrix as uniform matrix by ignoring the nonuniform x,y values just via adding the keyword nonuniform.

    plot $Data matrix            u -1:0:3
    plot $Data nonuniform matrix u -1:0:3
    

    Otherwise it would be:

    stats $Data nonuniform matrix
    N = STATS_size_x
    plot $Data nonuniform matrix u -1:(int($0)%N):3
    

    which I wouldn't call very user-friendly.
    Is there any practical example where you would need the linear index of a matrix?

     
  • Ethan Merritt

    Ethan Merritt - 2023-03-16
    • Status: pending-accepted --> closed-accepted
     

Log in to post a comment.