IT++ Logo
Conversion table between IT++ syntax and Matlab/Octave

Here we provide a conversion table between Matlab/Octave and IT++ syntax. This table is intended to help with the transition from Matlab/Octave programming to IT++, but it is not an exhaustive list of possible operations.



In what follows,

  • a, b denote vectors (assumed to be column vectors in Matlab/Octave notation),
  • A, B denote matrices,
  • x is a scalar,
  • k, l, n are indices


Vector indexing and manipulation:

a.length() // length(a)
a(0) // a(1)
a(1) // a(2)
a(k-1) // a(k)
a(k-1)=x; or a.set(k-1,x); // a(k)=x;
a.left(k) // a(1:k)
a.right(k) // a(end-k+1:end)
a.mid(k,l) // a(k:k+l-1)
a.del(k); // a=[a(1:k-1); a(k+1:end)];
concat(a,b) // [a; b] (or [a.' b.'].')
a.clear(); // a=zeros(size(a)); (or a=complex(zeros(size(a)));)
to_cmat(a) // complex(a) (assuming a real-valued)

Note that indexing in IT++ starts at 0, whereas indexing in Matlab starts at 1. Also note that Matlab/Octave does distinguish between column and row vectors, whereas IT++ does not.

Matrix indexing and manipulation:

A.rows() // size(A,1)
A.cols() // size(A,2)
A(k-1,l-1) // A(k,l)
A.set(k-1,l-1,x) // A(k,l)=x
A.get_col(k-1) // A(:,k)
A.get_row(k-1) // A(k,:)
A.set_col(k-1,a) // A(:,k)=a
A.set_row(k-1,a) // A(k,:)=a
A.append_row(a) // A=[A; a.']
A.append_col(a) // A=[A a]
A.transpose() // A.'
A.clear() // A=zeros(size(A)) [or A=complex(zeros(size(A)))]
to_cmat(A) // complex(A) (assuming a real-valued)



Some vector and matrix algebra:

a+b // a+b
a-b // a-b
elem_mult(a,b) // a.*b (elementwise product)
a*b // a.'*b (inner product)
conj(a)*b // a'*b (inner product)
outer_product(a,b) // a*b.' (outer product)
elem_div(a,b) // a./b
A+B // A+B
A-B // A-B
A*B // A*B
elem_mul(A,B) // A.*B
elem_div(A,B) // A./B
ls_solve_od(A,b) // A\b (assuming the system is overdetermined)



Special matrices and vectors:

zeros(n,n) // zeros(n,n)
zeros_c(n,n) // complex(zeros(n,n))
eye(n) // eye(n)
eye_c(n) // complex(eye(n))
linspace(alpha,beta,n) // linspace(alpha,beta,n)



Hardcoded initializations:

mat X="1.1 1.2; 2.1; 2.2"; // X=[1.1 1.2; 2.1 2.2];
ivec a="1 2 3 4 5"; // a=[1; 2; 3; 4; 5]; (or a=[1 2 3 4 5].';)
ivec a="1:-3:-8"; // a=1:-3:-8;
itpp::outer_product
Mat< Num_T > outer_product(const Vec< Num_T > &v1, const Vec< Num_T > &v2, bool hermitian=false)
Outer product of two vectors v1 and v2.
Definition: vec.h:1021
itpp::concat
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.
Definition: array.h:486
itpp::Vec::ivec
Vec< int > ivec
Definition of integer vector type.
Definition: vec.h:541
itpp::conj
cvec conj(const cvec &x)
Conjugate of complex value.
Definition: elem_math.h:226
itpp::eye
template void eye(int, mat &)
Template instantiation of eye.
itpp::ls_solve_od
bool ls_solve_od(const mat &A, const vec &b, vec &x)
Solves overdetermined linear equation systems.
Definition: ls_solve.cpp:424
itpp::elem_mult
Mat< Num_T > elem_mult(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise multiplication of two matrices.
Definition: mat.h:1582
itpp::Mat::mat
Mat< double > mat
Default Matrix Type.
Definition: mat.h:482
itpp::hermitian_transpose
void hermitian_transpose(const Mat< T > &m, Mat< T > &out)
Definition: matfunc.h:318
itpp::linspace
vec linspace(double from, double to, int points)
linspace (works in the same way as the MATLAB version)
Definition: specmat.cpp:106
itpp::transpose
void transpose(const Mat< T > &m, Mat< T > &out)
Transposition of the matrix m returning the transposed matrix in out.
Definition: matfunc.h:308
itpp::eye_c
ITPP_EXPORT cmat eye_c(int size)
A Double Complex (size,size) unit matrix.
itpp::zeros
ITPP_EXPORT vec zeros(int size)
A Double vector of zeros.
itpp::zeros_c
ITPP_EXPORT cvec zeros_c(int size)
A Double Complex vector of zeros.
itpp::elem_div
Mat< Num_T > elem_div(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise division of two matrices.
Definition: mat.h:1688
itpp::Mat::to_cmat
cmat to_cmat(const Mat< T > &m)
Converts a Mat<T> to cmat.
Definition: converters.h:232
SourceForge Logo

Generated on Thu Apr 11 2019 00:00:00 for IT++ by Doxygen 1.8.18