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

"Matrix partitioning into sub matrices"

Tags: None
(comma "," separated)
poqovic
Registered Member
Posts
9
Karma
0
OS
Hello,

I have problems with partitioning a MatrixXd into submatrices and using them for manipulation. All i get is copy of submatrices. When i change elements of submatrix, we got only local copy changes(no changes in container matrixXd). This means i am not able to get sub matrices with referance. Sample code below,

Code: Select all
#include "ThirdParty/Eigen/Eigen"
#include <stdio.h>
#include <stddef.h>
#include <iostream>
#include <time.h>
#include <windows.h>
#include <Vector>





typedef Eigen::MatrixXd yamMatrix;
typedef Eigen::Matrix<yamScalar,3,3> yamMatrix33;
typedef Eigen::Matrix<yamScalar,4,3> yamMatrix43;
typedef Eigen::Matrix<yamScalar,4,4> yamMatrix44;
typedef Eigen::Matrix<yamScalar,6,6> yamMatrix66;
typedef Eigen::VectorXd yamVector;
typedef Eigen::Vector4d yamVector4;
typedef Eigen::Vector3d yamVector3;
typedef Eigen::Vector2d yamVector2;



int  main(void){
yamMatrix m;
yamMatrix mtr;
int i;
m.resize(4,4);
m<<1,2,3,4,
   5,6,7,8,
   9,10,11,12,
   13,14,15,16;
mtr=m.topLeftCorner(2,2);
mtr(0,0)=-123;
cout<<mtr<<"\n\n\n";
cout<<m;




cin>>i;
  return 0;

}

}


the output is:
Code: Select all
mtr=-123 2
     5   6
m=1 2 3 4
  5 6 7 8
  9 10 11 12
  13 14 15 16


any suggestions?
jitseniesen
Registered Member
Posts
204
Karma
2
By itself, m.topLeftCorner(2,2) is an expression of type Eigen::Block<yamMatrix> and is a reference to the block in the top left corner of m. However, you assign it to a variable of type yamMatrix and the implicit type cast makes a copy. If you want a reference to the block, you should declare mtr to be of type Eigen::Block<yamMatrix> .
poqovic
Registered Member
Posts
9
Karma
0
OS
This solved problem thank you,

And another question, is there anyway to protect same row and columun index of reference block after resizing matrix, i want to automatically decrease sub blocks indices after i delete some block that's row count is same as "m" and columun count is less than "m" ?

this will make possible to delete some objects that containts reference blocks to m.

thank you.
jitseniesen
Registered Member
Posts
204
Karma
2
I do not understand what you want, but I suspect it is not possible.


Bookmarks



Who is online

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