in reply to Re^2: How to output matrix data from Math:;MatrixReal into a Hash or an Array
in thread How to output matrix data from Math:;MatrixReal into a Hash or an Array
The documentation for the Math::MatrixReal module discusses the element method, and the row method. Since the row method (inconveniently, in this case) generates a new 1xN matrix object, it's not as useful for file dumps as "element", which just returns plain old values.
All you really have to do is iterate over the rows, over the columns, and build up a CSV file. I chose to use Text::CSV in this solution, but it's so trivial that it would probably be easier and no less maintainable to just generate your own CSV:
use Text::CSV; use Math::MatrixReal; my $mref = [ [ '5', '4', '4', '2', '4' ], [ '9', '6', '4', '4', '3' ], [ '2','73','96', '6', '8' ], [ '2', '4', '9','87', '8' ], [ '2', '4','10', '6', '8' ], ]; my $matrix = Math::MatrixReal->new_from_rows( $mref ); # At this point $matrix is a Math::MatrixReal object that # resembles the one you showed us a Data::Dumper dump of. my $csv = Text::CSV->new; foreach my $row_num ( 1 .. 5 ) { $csv->print(*STDOUT, [ map { $matrix->element($row_num,$_) } 1 .. 5 +] ); print {*STDOUT} "\n"; }
Substitute *STDOUT for your own output file handle, of course.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to output matrix data from Math:;MatrixReal into a Hash or an Array
by Laurent_R (Canon) on May 13, 2014 at 09:15 UTC | |
by davido (Cardinal) on May 13, 2014 at 13:58 UTC | |
by Laurent_R (Canon) on May 13, 2014 at 15:37 UTC | |
by John007 (Acolyte) on May 15, 2014 at 04:27 UTC | |
by davido (Cardinal) on May 15, 2014 at 05:22 UTC | |
by John007 (Acolyte) on May 16, 2014 at 15:33 UTC |