diff --git a/stuff/printing.hh b/stuff/printing.hh index 2f66f8920aa5c65df1e4f774d5a1bb494bf30591..924c94bd0f621610b0554d1c81394b8a820a822c 100644 --- a/stuff/printing.hh +++ b/stuff/printing.hh @@ -97,6 +97,28 @@ void printSparseRowMatrixMatlabStyle(const T& arg, const std::string name, strea } } + +/** \brief print a ISTLMatrix (or any interface conforming object) to a given stream in matlab (laodable-) format + \ingroup Matlab + **/ +template <class MatrixType, class stream> +void printISTLMatrixMatlabStyle(const MatrixType& arg, const std::string name, stream& out) +{ + typedef typename MatrixType::ConstRowIterator ConstRowIteratorType; + typedef typename MatrixType::ConstColIterator ConstColIteratorType; + + ConstRowIteratorType rowEnd = arg.end(); + for (ConstRowIteratorType row = arg.begin(); row != rowEnd; ++row) { + ConstColIteratorType colEnd = row->end(); + for (ConstColIteratorType col = row->begin(); col != colEnd; ++col) { + const int rowIndex = row.index() + 1; + const int colIndex = col.index() + 1; + out << name << "(" << rowIndex << "," << colIndex << ")=" << std::setprecision(matlab_output_precision) << (*col) + << ";\n"; + } + } +} + /** \brief print a discrete function (or any interface conforming object) to a given stream in matlab (laodable-) format \ingroup Matlab **/