This forum has been archived. All content is frozen. Please use KDE Discuss instead.

reading 3D matrix

Tags: None
(comma "," separated)
nicolew
Registered Member
Posts
1
Karma
0

reading 3D matrix

Thu Aug 16, 2012 9:28 pm
Hi everyone,

I loaded a 3D matrix by the following codes in C++:

Code: Select all
#include <conio.h>
//#include <stdio.h>
#include <iostream>
#include <Eigen/Dense>
using namespace Eigen;
using namespace std;
#include <iostream>
#include <fstream>
#include <string>


int main () {
  int line;
  int X = 3;
  int Y = 3;
  int Z = 3;
  double a[3][3][3];
  ifstream myfile;
  myfile.open("example.txt",ios::in);
  int size = 0;
  int count=0;
  if (myfile.is_open())
  {
    myfile>>size;
    for (int i = 0; i < X; i++)
    {
      for (int j = 0; j < Y; j++)
      {
        for (int k = 0; k < Z; k++)
        {
          myfile>>a[i][j][k];
        }   
      }   
    }
   
  }
  else cout << "Unable to open file";
  getch(); 
}

my example.txt is as: 27 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
I want to select the inner part of this 3D matrix by Eigen but I do not how I should use, can anyone help me?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: reading 3D matrix

Wed Aug 22, 2012 9:17 am
What do you mean by inner part? a 2D slice? Anyway, I think Map is what you are looking for:

http://eigen.tuxfamily.org/dox-devel/cl ... _1Map.html


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]