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

Set matrix row

Tags: None
(comma "," separated)
mpmcl
Registered Member
Posts
19
Karma
0

Set matrix row

Fri Jun 12, 2009 2:43 pm
I am very new to Eigen (v2.0.2) and, from the tutorial, I thought it was possible to set values for a single row of a matrix which is something I need to do. However, I am getting dimension mismatch errors originating from

Core/block.h line 247

As a test, I tried setting a row of MatrixXd G(12, 3), as follows:

Vector3d tempVec = Vector3d::Ones();
G.row(3) = tempVec;

This compiles but has a runtime error. Is there some way to do this row-wise assignment? [Note: I need column-wise assignment, too.]

Thanks in advance.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

RE: Set matrix row

Fri Jun 12, 2009 3:11 pm
This is because tempVec is a column vector while G.row(3) is a row vector. Actually, in most cases this transposition is automatic, however, in your case one vector has compile time size (Vector3d) while the other has a dynamic size (a row of MatrixXd) and then our test detect that even with a transposition the sizes do not match. So two solutions:

1 - you can explicitly transpose the rhs, e.g.:
Code: Select all
G.row(3) = tempVec.transpose();


2 - since it seems the number of column of G is known at compile time I suggest you to declare it like this:
Code: Select all
Matrix G;


Now, Benoit and I have to decide whether we want to allow automatic transpositions in such a case. The test in Assign.h could be:

Code: Select all
bool NeedToTranspose =
                  ((int(Derived::RowsAtCompileTime) == 1 && int(OtherDerived::ColsAtCompileTime) ==1)
               || (int(Derived::ColsAtCompileTime) == 1 && int(OtherDerived::RowsAtCompileTime) == 1))
                && int(Derived::SizeAtCompileTime) != 1


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]