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

本文转自feisky博客园博客,原文链接:http://www.cnblogs.com/feisky/archive/2009/11/24/1609761.html,如需转载请自行联系原作者



相关文章
|
9月前
rank()、dense-rank()、row-number()的区别
rank()、dense-rank()、row-number()的区别
61 0
Mysql8.0习题系列(八):窗口函数(一篇学会rank、dense_rank、row_number使用,超详细~)
Mysql8.0习题系列(八):窗口函数(一篇学会rank、dense_rank、row_number使用,超详细~)
|
数据采集 存储 传感器
Paper:《Disc and Drum Brake Dynamometer Squeal Noise Test Procedure》翻译及其解读
Paper:《Disc and Drum Brake Dynamometer Squeal Noise Test Procedure》翻译及其解读
|
关系型数据库 MySQL
MySQL - 排序函数 Rank() Over()、Dense_rank() Over()、Row_number() Over()
MySQL - 排序函数 Rank() Over()、Dense_rank() Over()、Row_number() Over()
276 0
MySQL - 排序函数 Rank() Over()、Dense_rank() Over()、Row_number() Over()
|
机器学习/深度学习 人工智能
Collatz Problem----map妙用
题目描述 A sequence a={a1,a2,a3,…} is determined as follows: The first term s is given as input. Let f(n) be the following function: f(n)=n/2 if n is even, and f(n)=3n+1 if n is odd. ai=s when i=1, and ai=f(ai−1) when i>1. Find the minimum integer m that satisfies the following condition:
129 0
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
86 0
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
116 0
|
C++
Data Structures and Algorithms (English) - 6-9 Sort Three Distinct Keys(20 分)
Data Structures and Algorithms (English) - 6-9 Sort Three Distinct Keys(20 分)
88 0
Data Structures and Algorithms (English) - 6-10 Sort Three Distinct Keys(30 分)
Data Structures and Algorithms (English) - 6-10 Sort Three Distinct Keys(30 分)
91 0