Skip to content

Instantly share code, notes, and snippets.

@jmbr
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmbr/3c0104d5665667686d6d to your computer and use it in GitHub Desktop.
Save jmbr/3c0104d5665667686d6d to your computer and use it in GitHub Desktop.
/*
* Example: spy("foobar.ppm", A);
*/
int spy(std::string const& ppmfile, arma::mat const& M) {
ofstream ofs(ppmfile);
if (!ofs.is_open())
return -1;
ofs << "P3\n" << M.n_rows << " " << M.n_cols << "\n1\n";
for (unsigned i = 0; i < M.n_rows; ++i) {
for (unsigned j = 0; j < M.n_cols; ++j) {
for (unsigned k = 0; k < 3; ++k)
ofs << (M(i, j) == 0) << " ";
ofs << " ";
}
ofs << "\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment