MATLAB Eigen Notes
[Y,IX] = sort(Y,dim,mode)
igl::sort(X,dim,mode,Y,IX)
MATLAB version allows Y to be a multidimensional matrix, but the Eigen version is only for 1D or 2D matrices.
B(i:(i+w),j:(j+h)) = A(x:(x+w),y:(y+h))
B.block(i,j,w,h) = A.block(i,j,w,h)
MATLAB version would allow w and h to be non-positive since the colon operator evaluates to a list of indices, but the Eigen version needs non-negative width and height values.
max(A(:))
A.maxCoeff()
Find the maximum coefficient over all entries of the matrix.
min(A(:))
A.minCoeff()
Find the minimum coefficient over all entries of the matrix.
eye(w,h)
MatrixXd::Identity(w,h), MatrixXf::Identity(w,h), etc.
A(i:(i+w),j:(j+h)) = eye(w,h)
A.setIdentity()
[I,J,V] = find(X)
igl::find(X,I,J,V)
Matlab supports finding subscripts (I and J) as well as indices (just I), but so far igl::find only supports subscripts. Also, igl::find requires X to be sparse.
X(:,j) = X(:,j) + x
X.col(j).array() += x
Acol_sum = sum(A,1)
Arow_sum = sum(A,2)
Adim_sum = sum(Asparse,dim)
Acol_sum = A.colwise().sum()
Arow_sum = A.rowwise().sum()
igl::sum(Asparse,dim,Adim_sum)
Currently the igl version only supports sparse matrix input (and dim must be 1 or 2)
D = diag(M)
igl::diag(M,D)
Extract the main diagonal of a matrix. Currently igl version supports sparse only.
M = diag(D)
igl::diag(D,M)
Construct new square matrix M with entries of vector D along the diagonal. Currently igl version supports sparse only.
[Y,I] = max(X,[],dim)
igl::mat_max(X,dim,Y,I)
Matlab has a bizarre convention of passing [] as the second argument to mean take the max/min along dimension dim.
Y = max(X,[],1)
Y = max(X,[],2)
Y = min(X,[],1)
Y = min(X,[],2)
Y = X.colwise().maxCoeff()
Y = X.rowwise().maxCoeff()
Y = X.colwise().minCoeff()
Y = X.rowwise().minCoeff()
Matlab allows you to obtain the indices of extrema see mat_max
C = A.*B
C = (A.array() * B.array()).matrix()
C = A.^b
C = A.array().pow(b).matrix()
A(B == 0) = C(B==0)
A = (B.array() == 0).select(C,A)
C = A + B'
SparseMatrixType BT = B.transpose()
SparseMatrixType C = A+BT;
Do not attempt to combine .transpose() in expression like this:
C = A + B.transpose()
[L,p] = chol(A)
SparseLLT<SparseMatrixType> A_LLT(A.template triangularView<Lower>())
SparseMatrixType L = A_LLT.matrixL();bool p = (L*0).eval().nonZeros()==0;
Do not attempt to use A in constructor of A_LLT like this:
SparseLLT<SparseMatrixType> A_LLT(A)

Do not attempt to use A_LLT.succeeded() to determine if Cholesky factorization succeeded, like this:
bool p = A_LLT.succeeded()
X = U\(L\b)
X = b;
L.template triangularView<Lower>().solveInPlace(X);
U.template triangularView<Upper>().solveInPlace(X);
Expects that L and U are lower and upper triangular matrices respectively
B = repmat(A,i,j)
igl::repmat(A,i,j,B)
So far igl::repmat is only implemented for dense matrices.
I = low:step:hi
igl::colon(low,step,hi,I)
IGL version should be templated enough to handle same situations as matlab's colon. The matlab keyword end does not correspond in the C++ version. You'll have to use M.size(),M.rows() or whatever.
O = ones(m,n)
Matrix* O = Matrix*::Ones(m,n)
O = zeros(m,n)
Matrix* O = Matrix*::Zero(m,n)
B = A(I,J)
B = A(I,:)
igl::slice(A,I,J,B)
B = igl::slice(A,I,igl::colon(0,A.cols()-1))
This is only for the case when I and J are lists of indices and not vectors of logicals.
B(I,J) = A
B(I,:) = A
igl::slice_into(A,I,J,B)
B = igl::slice_into(A,I,igl::colon(0,B.cols()-1))
This is only for the case when I and J are lists of indices and not vectors of logicals.
M = mode(X,dim)
igl::mode(X,dim,M)
B = arrayfun(FUN, A)
B = A.unaryExpr(ptr_fun(FUN))
If FUN is templated, the templates must be fully resolved.
B = fliplr(A)
B = flipud(A)
B = A.rowwise().reverse().eval()
B = A.colwise().reverse().eval()
The .eval() is not necessary if A != B
B = IM(A)
B = A.unaryExpr(bind1st(mem_fun( 
  static_cast<VectorXi::Scalar&(VectorXi::*)(VectorXi::Index)>
  (&VectorXi::operator())), &IM)).eval();
  
Where IM is an "index map" column vector and A is an arbitrary matrix. The .eval() is not necessary if A != B
A = sparse(I,J,V)
// build std::vector<Eigen::Triplet> IJV
A.setFromTriplets(IJV);
        
IJV and A should not be empty! (this might be fixed)
A = min(A,c);
C.array() = A.array().min(c);
        
Coefficient-wise minimum of matrix and scalar (or matching size matrix)
IP = I(P==0);
VectorXi IP = I;
IP.conservativeResize(stable_partition(
  IP.data(), 
  IP.data()+IP.size(), 
  [&P](int i){return P(i)==0;})-IP.data());
        
Where I and P are vectors. Requires C++11 and #include <algorithm>
a = any(A(:))
bool a = any_of(A.data(),A.data()+A.size(),[](bool a){ return a;});
Casts Matrix::Scalar to bool.
Eigen's "ASCII Quick Reference" with MATLAB translations
IGL Lib Tutorial