diff options
Diffstat (limited to 'doc/examples/Tutorial_simple_example_dynamic_size.cpp')
-rw-r--r-- | doc/examples/Tutorial_simple_example_dynamic_size.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/examples/Tutorial_simple_example_dynamic_size.cpp b/doc/examples/Tutorial_simple_example_dynamic_size.cpp new file mode 100644 index 000000000..0f0280e0e --- /dev/null +++ b/doc/examples/Tutorial_simple_example_dynamic_size.cpp @@ -0,0 +1,22 @@ +#include <Eigen/Core> +#include <iostream> + +using namespace Eigen; + +int main() +{ + for (int size=1; size<=4; ++size) + { + MatrixXi m(size,size+1); // a (size)x(size+1)-matrix of int's + for (int j=0; j<m.cols(); ++j) // loop over columns + for (int i=0; i<m.rows(); ++i) // loop over rows + m(i,j) = i+j*m.rows(); // to access matrix coefficients, + // use operator()(int,int) + std::cout << m << "\n\n"; + } + + VectorXf v(4); // a vector of 4 float's + // to access vector coefficients, use either operator () or operator [] + v[0] = 1; v[1] = 2; v(2) = 3; v(3) = 4; + std::cout << "\nv:\n" << v << std::endl; +} |