zoukankan      html  css  js  c++  java
  • MRPT学习笔记Matrices and Vectors

    头文件:

    image

    Matrices

    Matrices are implemented as class templates in MRPT, but the followingtwo types are provided for making programs more readable:


    typedef CMatrixTemplateNumeric<f loat> CMatrixFloat ;
    typedef CMatrixTemplateNumeric<double> CMatrixDouble ;

    A matrix with any given size can be created by passing it at construction time, or otherwise it can be resized later as shown in this example:


    CMatrixDouble M( 2 , 3 ) ; // Create a 2x3 matrix
    cout << M( 0 , 0 ) << endl ; // Pr int out t he l e f t −top element
    CMatrixDouble A; // Another way of c r e a t i ng
    A. s e t S i z e ( 3 , 4 ) ; // a 2x3 matrix
    A( 2 , 3 ) = 1 . 0 ; // Change t he bottom−r i g h t element


    A matrix can be resized at any time, and the contents are preserved ifpossible. Notice also in the example how the element at the r’th row and c’th column can be accessed through M(r, c). Sometimes, predefined values must be loaded into a matrix, and writing all the assignments element by element can be tedious and error prone. In those cases, better use this constructor:


    const double numbers [ ] = {
    1 , 2 , 3 ,
    4 ,5 ,6 } ;
    CMatrixDouble N(2 , 3 , numbers ) ;
    cout << ” I n i t i a l i z e d matr ix : ” << endl << N << endl ;

    固定大小矩阵:

    image

    文件读写:

    CMatrixDouble H,Z ,D;
    H. loadFromTextFi le ( ”H. txt ” ) ; // H <− ’H. t x t ’
    H. e i genVe c tor s (Z ,D) ; // Z: e i g env e c t or s , D: e i g e nv a l u e s
    Z . saveToTextFi le ( ”Z . txt ” ) ; // Save Z in ’Z. t x t ’

    Vectors

    The base class for vectors is the standard STL container std::vector,

    typedef s td : : vector<f loat> v e c t o r f l o a t ;
    typedef s td : : vector<double> ve c tor doubl e ;

    Resize

    ve c tor doubl e V( 5 , 1 ) ; // Create a v e c t or wi th 5 ones .
    V. r e s i z e ( 1 0 ) ;
    cout << V << endl ; // Pr int out t he v e c t or to c onsol e

    文件读写:

    ve c tor doubl e v ;
    loadVector ( CFi leInputStream ( ” in . txt ” ) , v )

    ve c tor doubl e v ( 4 , 0 ) ; // [ 0 0 0 0]
    vectorToTextFi l e ( v , ”o1 . txt ” ) ; // Save as row
    vectorToTextFi l e ( v , ”o2 . txt ” , true ) ; // Append a new row
    vectorToTextFi l e ( v , ”o3 . txt ” , fal se , true ) ; // Save as a column

    Serializing
    If you prefer to serialize the vectors in binary form (see chapter 10), that can be done as simply as:


    ve c tor doubl e v = l i n s p a c e ( 0 , 1 , 1 0 0 ) ; // [ 0 . . . 1]
    CFi leOutputStream( ”dump. bin ” ) << v ;

    基本矩阵(向量)运算

    image

    image

    一些优化的矩阵(向量)运算

    image

    提取子阵

    image

    image

    矩阵合并

    image


    注意:在使用CMatrixFixedNumeric时候编译可通过,但会出现Debug未知错误,原因是CMatrixFixedNumeric.h这个头文件文件名小写了,改成首字母大写格式即可。

  • 相关阅读:
    我的公众号 猫和大叔(maohedashu)
    centos编译php时出现make: *** [sapi/fpm/phpfpm] Error 1
    如何在centos和linux等主机上安装 pstree
    如何在centos下卸载干净nginx
    监控感悟(一)
    ant design vue 获取上传图片的像素
    ant vue中atree默认展开指定的树节点不起作用
    uniapp中组件属性设置不生效的解决方案
    vue+canvas实现简易画板
    ant design vue级联选择懒加载省市区三级数据
  • 原文地址:https://www.cnblogs.com/feisky/p/1609761.html
Copyright © 2011-2022 走看看