Dear All,

I am asking if it is possilbe to get the nth from a file then apply the a matrix dot multiplication on that line. The matrix is from another file.

I have a xyzfile with lines like:

Code:

x1 y1 z1
x2 y2 z2
x3 y3 z3
...
...
x12 y12 z12
x13 y13 z13
...
...

I have a matrix saved in file called matrix with lines:

Code:

a11 a12 a13
a21 a22 a23
aa31 a32 a33

I found I can do dot multiplication between a matrix and a list of coordinates by:

Code:

awk 'NR==FNR {
for(i=1;i<=NF;i++)A[NR,i]=$i
next
}
{
for(i=1;i<=NF;i++){
t=0
for(j=1;j<=NF;j++)
t+=A[i,j]*$j
printf ("%f%s", t, FS)
}
print ""
}' matrixfile xyzfile

This will do the do multiplication line by line until the end of xyzfile.

However, my question is I want to dot multiply only the No.i line in the xyzfile by the matrix.

I do not want to use another awk and then redirect to a file include that line, then multiply it with matrix by the above code. I do not want any redundant file generated. I hope to do everything in a single awk simply and the running speed should be fast.

How could I change the above code slightly to achieve my goal? Is that possible to use getline in this case?

I would thank you for your kind help!!!