Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between two matrix 2

Status
Not open for further replies.

hill007

Technical User
Mar 9, 2004
60
US
I am sending this email, which I had sent earlier but with slight different approach. I have two large matrix, with same dimensions. I want to compare matrix 1 file with matrix 2 file.
I just now want to subtract the cells of matrix 1 from matrix 2.
Example

Matrix 1

2 3 6 9 12
-3 4 7 -2 -6
3 10 4 8 14

Matrix 2

3 1 5 7 14
-1 7 3 -1 -8
2 6 1 12 18

Subtracting matrix 1 from matrix 2:

Final Matrix 2 would be:

-1 2 1 2 -2
-2 -3 4 -1 2
1 4 3 -4 -4


Thankyou allways.


Any help will be tremendously appreciated.
 
matrix.awk
Code:
NR==FNR{for(i=1;i<=NF;++i)a[FNR,i]=$i;next}
{for(i=1;i<=NF;++i)$i=a[FNR,i]-$i;print}
awk95 -f matrix.awk Matrix1 Matrix2 > newMatrix2

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top