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

I just learned how to use PDL. The problem is that my data (matrix) is in an external file.
How can i change change it into a PDL data structure?
I tried the code below but, the values in $s are still ones.


use PDL;
use PDL::Matrix;
use PDL::NiceSlice;
use PDL::AutoLoader;
use PDL::IO::Dumper;

my $s = ones(10,10); # There are 10 columns and 10 rows
my $k = 0;
while (my $line = <$fileHandler>)
{
        $s(0:9,0:$k) = $line;
        $k++;
}


Regards and thank you,

Herve
Posted
Comments
Uilleam 8-Nov-11 16:13pm    
What is in your $fileHandler? Did you leave out the code that defines it? If so, Perl will glob for a null filename which will probably produce nothing and the loop won't do anything. I suspect you may want to have an explicit open() and use a file handle there.
The_Real_Chubaka 8-Nov-11 16:21pm    
Hi. Thank you for wanting to help me.
I already got help. I just have to find out how to delete this question now.
My fileHandler is a handle to a file that contains space separated values.
Uilleam 8-Nov-11 17:15pm    
Could you answer your question with a snippet of code that shows the solution? That would be the best way to close this off I think.

Glad you got it solved.
The_Real_Chubaka 8-Nov-11 18:07pm    
I don't think they allow that. ie: It will give me more points. Especially if i 'accept' my own answer; i think they might even give me a warning. That's because it will also increase the number of pints i have.

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