Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • e31fa09
  • /
  • src
  • /
  • matlabOutputs.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:6bde39710a98211feb40e51698b8899a5b218a12
directory badge
swh:1:dir:a182c55e93ceee8e3a35d88e8da2daa576d94fc5

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
matlabOutputs.cpp
#include "matlabOutputs.h"

#include <fstream>
#include <iomanip>

#define EIGEN_DONT_ALIGN_STATICALLY
#include <Eigen\Dense>

using namespace std;
using namespace Eigen;

void mat_to_file(const Eigen::MatrixXd& mat, const string &var_name, const string &file_name, const bool &overwrite)
{
	ofstream ofs;
	if(overwrite) ofs.open(file_name, ofstream::out | ofstream::trunc);
	else ofs.open(file_name, ofstream::out | ofstream::app);

	ofs << setprecision(20);

	ofs << var_name;
	ofs << " = [";
	ofs << mat;
	ofs << "];\n\n";

	ofs.close();
}

void mat_to_file(const Eigen::MatrixXi& mat, const string &var_name, const string &file_name, const bool &overwrite)
{
	ofstream ofs;
	if (overwrite) ofs.open(file_name, ofstream::out | ofstream::trunc);
	else ofs.open(file_name, ofstream::out | ofstream::app);

	ofs << setprecision(20);

	ofs << var_name;
	ofs << " = [";
	ofs << mat;
	ofs << "];\n\n";

	ofs.close();
}

void vec_to_file(const Eigen::VectorXd& vec, const string &var_name, const string &file_name, const bool &overwrite)
{
	ofstream ofs;
	if (overwrite) ofs.open(file_name, ofstream::out | ofstream::trunc);
	else ofs.open(file_name, ofstream::out | ofstream::app);

	ofs << setprecision(20);

	ofs << var_name;
	ofs << " = [\n";
	ofs << vec;
	ofs << "\n];\n\n";

	ofs.close();
}

void vec_to_file(const Eigen::VectorXi& vec, const string &var_name, const string &file_name, const bool &overwrite)
{
	ofstream ofs;
	if (overwrite) ofs.open(file_name, ofstream::out | ofstream::trunc);
	else ofs.open(file_name, ofstream::out | ofstream::app);

	ofs << setprecision(20);

	ofs << var_name;
	ofs << " = [\n";
	ofs << vec;
	ofs << "\n];\n\n";

	ofs.close();
}

void mesh2m(const Mesh& mesh, const string &file_name, const bool &overwrite)
{
	MatrixXd x_X(mesh.nodes.size(), 5);
	MatrixXi faces2(3, mesh.faces.size());
	VectorXi isEOL(mesh.nodes.size());
	for (int i = 0; i < mesh.nodes.size(); i++) {

		if (mesh.nodes[i]->EoL) isEOL(i) = 1;
		else isEOL(i) = 0;
		x_X(i, 0) = mesh.nodes[i]->x[0];
		x_X(i, 1) = mesh.nodes[i]->x[1];
		x_X(i, 2) = mesh.nodes[i]->x[2];
		x_X(i, 3) = mesh.nodes[i]->verts[0]->u[0];
		x_X(i, 4) = mesh.nodes[i]->verts[0]->u[1];
	}

	for (int i = 0; i < mesh.faces.size(); i++) {
		faces2.col(i) = Vector3i(mesh.faces[i]->v[0]->node->index, mesh.faces[i]->v[1]->node->index, mesh.faces[i]->v[2]->node->index);
	}

	mat_to_file(x_X, "x_X", file_name, overwrite);
	vec_to_file(isEOL, "isEol", file_name, false);
	VectorXi vvv(3);
	vvv << 1, 1, 1;
	mat_to_file(faces2.colwise() += vvv, "faces", file_name, false);
}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API