Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I posted this on Perlguru but, i have not gotten a reply yet.
I' just hoping to get one here.

Anyway, i have data (numbers) in a file data.txt.

I would like to import it and use it as a matrix.
ie: be able to use a matematical operation on only one row, or only one column. And Or on only one element.

I have tried a few things:

1) I know you can create a matrix like this:

my @matrix1 = ( 
[qw(0 0 0 0)], 
[qw(0 0 1 0)], 
[qw(0 1 0 0)], 
[qw(1 0 0 0)], 
);


But i can only access one element at a time. eg: $matrix1[0][0]

2) I have tried to use the PDL::Matrix module. It has given me errors, of which i have not found the solution on Google.
I included it like this:

use PDL::Matrix;


That line gave me no error. (I did install it, using CPAN)

When i tried to use it like this:
my $matrix2 = mpdl[[1,2,3],[4,5,6],[7,8,9]]; 
#or like this: 
my $matrix2 = pdl[[1,2,3],[4,5,6],[7,8,9]]; 
#or even like this: 
my $matrix2 = PDL::Matrix->pdl[[1,2,3],[4,5,6],[7,8,9]];




All of them gave me the error below:

Can't locate object method "pdl" via package "PDL::Matrix" at /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/PDL/Matrix.pm line 134.



I have been doing the two examples for practice but, what i want to do it import my file and be able to do all the operations i described above. I still have to figure out how i will use the above method on my file handler.
The only thing that works so far is importing the file and reading one line at a time :(

Thank you for your help
Posted

1 solution

You might want to add this first:
use PDL;


If it still can't find the library. You need to specify the path to it or add it to the environment.
use lib "./PDL-2.4.3";


Check out this link for more info:
http://docstore.mik.ua/orelly/perl/prog3/ch31_13.htm[^]

Good luck!
 
Share this answer
 
Comments
The_Real_Chubaka 5-Nov-11 17:00pm    
Thanks. It works :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900