⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matlabfile.cpp

📁 Dolfin provide a high-performance linear algebra library
💻 CPP
字号:
// Copyright (C) 2003-2006 Johan Hoffman and Anders Logg.// Licensed under the GNU LGPL Version 2.1.//// Modified by Erik Svensson, 2003.// Modified by Andy R. Terrel, 2005.// Modified by Garth N. Wells, 2006.//// First added:  2003-02-17// Last changed: 2006-05-30#include <stdio.h>#include <dolfin/dolfin_log.h>#include <dolfin/Matrix.h>#include <dolfin/MatlabFile.h>#include <dolfin/Array.h>using namespace dolfin;//-----------------------------------------------------------------------------MatlabFile::MatlabFile(const std::string filename) : MFile(filename){  type = "MATLAB";}//-----------------------------------------------------------------------------MatlabFile::~MatlabFile(){  // Do nothing}//-----------------------------------------------------------------------------void MatlabFile::operator<<(Matrix& A){  // Open file  FILE *fp = fopen(filename.c_str(), "a");  // Write matrix in sparse format  fprintf(fp, "%s = [", A.name().c_str());  int ncols = 0;  Array<int> columns;  Array<real> values;    for (uint i = 0; i < A.size(0); i++)  {    A.getRow(i, ncols, columns, values);    for (int pos = 0; pos < ncols; pos++)    {      fprintf(fp, " %u %i %.15g", i + 1, columns[pos] + 1, values[pos]);      if ( i == (A.size(0) - 1) && (pos + 1 == ncols) )        fprintf(fp, "];\n");      else {        fprintf(fp, "\n");      }    }  }  fprintf(fp, "%s = spconvert(%s);\n", A.name().c_str(), A.name().c_str());    // Close file  fclose(fp);  message(1, "Saved matrix %s (%s) to file %s in sparse MATLAB format",          A.name().c_str(), A.label().c_str(), filename.c_str());}//-----------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -