I have 300+ objects with specific values for x,y,z coordinates, and I want to determine the distance between all 300+ objects and construct a matrix in the following fashion-

A B C A 0 10 3 B 4 0 7 C 4 1 0

where the values in the matrix are the distances between A and B, A and C etc. (I just made up the numbers). I've been given data like so,

s x y z A C 79.620 54.720 53.034 B C 81.822 54.071 50.027 C C 83.871 51.966 52.424 ...

And this equation for distance:

$d = sqrt(($rx1 - $rx2)**2 + ($ry1 - $ry2)**2 + ($rz1 - $rz2)**2)

s is a shape parameter that doesn't do anything for this calculation. I realize that I need to work with loops in order to do these crazy number of permutations, but I am not sure how to begin. I tried the following way to get a code to read and store the values in the file, but I could only get it read the first line.

open(IN, "template.xyz") or die; chomp($line = < IN >); ($b, @xyz) = split /\s+/, $line; while (chomp($line = < IN >)) { ($bb, @xyzvals) = split /\s+/, $line; for ($i=0; $i<@xyzvals; $i++) { $s{$bb}{$xyz[$i]} = $xyzvals[$i]; } } close(IN);

Any advice on reading/storing the values properly and how to go about doing the permutations?

Original content restored above by GrandFather

I have 300+ objects with specific values for certain coordinates, and I want to determine a value between all 300+ objects and construct a matrix. Any advice on reading/storing the values properly and how to go about doing the permutations? (question resolved)


In reply to Employing loops and constructing a matrix by doozy

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.