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

Define and initialize dynamic matrix

Tags: None
(comma "," separated)
donnss
Registered Member
Posts
7
Karma
0
I'm trying to define a dynamic matrix like this:
Code: Select all
Matrix<unsigned short, Eigen::Dynamic, Eigen::Dynamic> pixelData;

A far as I understood this defines a 2D dynamic matrix of unsigned short data type elements. Later on, during the execution of my code I get the matrix size I need and store those values, for example, in two variables:
Code: Select all
int width;
int height;

Now as I have the size of matrix dimensions I want to initialize my matrix accordingly. How to do it? What is the best way to do it? So far I'm thinking of using
Code: Select all
pixelData.resize(width, height);

however, I'm not sure if it is the right way to do it. Any thoughts?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Yes, this is the right way, but notice that the values of the coefficients are not initialized. You can then call

pixelData.setZero();

to initialize them to 0 if needed.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft