Dear Monks,

I am looking to find a way to convert a 2 column / 100,000 line file into a matrix. In this file, the columns represent X and Y values.

What I want to get is the following matrix, like so:

If I have x coordinates x1, x2, x3 and y coordinates y1, y2, y3, I want to get all possible combinations, like x1,y1, x1,y2, x1,y3, x2,y1, x2,y2, x2,y3, x3,y1,vx3,y2, x3,y3 - in the form of a matrix but I can't format it properly for this post :'(

I also want to get a population, which would be a count of how many times the coordinate (for example) (56,6 , 85,5) occurs and divide this by 100,000.

A few questions as I don't know how to begin:

1. the coordinates have 10 decimal points and I'd like to maybe round them up at 2, is there a way to do that before calculating the matrix?

2. is there a Perl module specifically for matrices? Does this http://docstore.mik.ua/orelly/perl/advprog/ch02_02.htm seem like a link that would help me? Also I tried some things from here https://www.biostars.org/p/60546/, specifically I tried this one-liner

perl -lane '$cnt{$_}++; END { foreach $key (keys %cnt) {print "$key\t$cnt{$key}"} }' input.txt

do you think it could be doing what I want? I know it's not giving me any population details but I'm not even sure if this code is for combining all coordinates?

IThe reason why I need this is to be able to plot a heat map later on with gnuplot.

Also another question for a potential gnuplot/Perl specialist here, is there a way for gnuplot to maybe "interpret" or count the occurrences on its own, without me having a population column or something like that in the file? Maybe if the input coordinates are already in the form of a matrix, gnuplot is able to count them and push this result into a heat map, representing the fractional population of the data?

I have a feeling that it might be a matter of "simply" having loops going through all entries or something like that? I would appreciate any hints/information as I don't know how to begin, I don't expect you to try and write the code for me but some guidance would be more than welcome.

Thank you all very much in advance, any information would be greatly appreciated.


In reply to convert columns into matrix and get population count? by fasoli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.