0
votes

I have a file, let's say 6 x 2 which contains the data of three 2 by 2 matrices:

1 2
3 2
1 5
6 2 
8 5 
2 7

Now I want to be able to plot specific matrices of that file. Like the matrix

1 5
6 2

For my other files where I have one dimensional data I use ::1::10 if I want to plot Data from the first ten lines.

Bit how can I do that for matrices?

1

1 Answers

1
votes

You could select the block/matrix of interest "manually" and then pass this preprocessed input to Gnuplot to visualize it. For example:

getMatrix(fName, i) = sprintf("<sed -n -e'%d,%dp' '%s'", 2*i-1, 2*i, fName)

plot getMatrix('test.dat', 2) matrix w image

Here, Gnuplot "sees" only the output of the sed command which filters from the file test.dat only lines 3 and 4, i.e., the matrix you show in your post.

EDIT:

The statement

getMatrix(fName, i) = sprintf("<sed -n -e'%d,%dp' '%s'", 2*i-1, 2*i, fName)

defines a function which for given file name and matrix index (assumed to be 1-based) constructs first a string containing the plotting command which is then passed to plot. For example, for i=1 and file test.dat, the command looks like <sed -n -e'1,2p' 'test.dat'. If one instructs Gnuplot to plot such a "thing", it executes the command after the leading < and plots its output (instead of the entire file test.dat). In this particular case, sed extracts only lines with line numbers (1-based) from 1 to 2 (inclusive).

In order to extend this for matrices of general size N (assuming that the file being processed has corresponding number of columns), one could for example do:

unset key

getMatrix(fName, N, i) = sprintf("<sed -n -e'%d,%dp' '%s'", (i-1)*N + 1, i*N, fName)

do for [i=1:2] {
    plot getMatrix('test.dat', 10, i) matrix w image
    pause 5
}

The only change here is the extra parameter N denoting the size of the individual matrices and how the range of rows is calculated...