matlab-to-eigen.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <html>
  2. <head>
  3. <title>MATLAB to Eigen</title>
  4. <style type="text/css">
  5. table
  6. {
  7. border-spacing: 0px;
  8. }
  9. tr.header th
  10. {
  11. border-bottom: 1px solid;
  12. background-color: #ffb;
  13. padding-left: 10px;
  14. padding-right: 20px;
  15. }
  16. tr.d0 td
  17. {
  18. background-color: #EEE;
  19. color: black;
  20. padding-left: 10px;
  21. padding-right: 20px;
  22. min-width: 200px;
  23. }
  24. tr.d1 td
  25. {
  26. background-color: #bcf;
  27. color: black;
  28. padding-left: 10px;
  29. padding-right: 20px;
  30. min-width: 200px;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <table>
  36. <tr class="header">
  37. <th>MATLAB</th>
  38. <th>Eigen</th>
  39. <th>Notes</th>
  40. </tr>
  41. <tr class=d0>
  42. <td><pre><code>[Y,IX] = sort(Y,dim,mode)</code></pre></td>
  43. <td><pre><code>igl::sort(X,dim,mode,Y,IX)</code></pre></td>
  44. <td>MATLAB version allows Y to be a multidimensional matrix, but the
  45. Eigen version is only for 1D or 2D matrices.</td>
  46. </tr>
  47. <tr class=d1>
  48. <td><pre><code>B(i:(i+w),j:(j+h)) = A(x:(x+w),y:(y+h))</code></pre></td>
  49. <td><pre><code>B.block(i,j,w,h) = A.block(i,j,w,h)</code></pre></td>
  50. <td>MATLAB version would allow w and h to be non-positive since the
  51. colon operator evaluates to a list of indices, but the Eigen version
  52. needs non-negative width and height values.</td>
  53. </tr>
  54. <tr class=d0>
  55. <td><pre><code>max(A(:))</code></pre></td>
  56. <td><pre><code>A.maxCoeff()</code></pre></td>
  57. <td>Find the maximum coefficient over all entries of the matrix.</td>
  58. </tr>
  59. <tr class=d1>
  60. <td><pre><code>min(A(:))</code></pre></td>
  61. <td><pre><code>A.minCoeff()</code></pre></td>
  62. <td>Find the minimum coefficient over all entries of the matrix.</td>
  63. </tr>
  64. <tr class=d0>
  65. <td><pre><code>eye(w,h)</code></pre></td>
  66. <td><pre><code>MatrixXd::Identity(w,h), MatrixXf::Identity(w,h), etc.</code></pre></td>
  67. <td></td>
  68. </tr>
  69. <tr class=d1>
  70. <td><pre><code>A(i:(i+w),j:(j+h)) = eye(w,h)</code></pre></td>
  71. <td><pre><code>A.setIdentity()</code></pre></td>
  72. <td></td>
  73. </tr>
  74. <tr class=d0>
  75. <td><pre><code>[I,J,V] = find(X)</code></pre></td>
  76. <td><pre><code>igl::find(X,I,J,V)</code></pre></td>
  77. <td>Matlab supports finding subscripts (I and J) as well as indices
  78. (just I), but so far igl::find only supports subscripts. Also,
  79. igl::find requires X to be sparse.</td>
  80. </tr>
  81. <tr class=d1>
  82. <td><pre><code>X(:,j) = X(:,j) + x</code></pre></td>
  83. <td><pre><code>X.col(j).array() += x</code></pre></td>
  84. <td></td>
  85. </tr>
  86. <tr class=d0>
  87. <td><pre><code>Adim_sum = sum(A,dim)</code></pre></td>
  88. <td><pre><code>igl::sum(A,dim,Adim_sum)</code></pre></td>
  89. <td>Currently the igl version only supports sparse matrix input (and
  90. dim must be 1 or 2)</td>
  91. </tr>
  92. <tr class=d1>
  93. <td><pre><code>D = diag(M)</code></pre></td>
  94. <td><pre><code>igl::diag(M,D)</code></pre></td>
  95. <td>Extract the main diagonal of a matrix. Currently igl version
  96. supports sparse only.</td>
  97. </tr>
  98. <tr class=d0>
  99. <td><pre><code>M = diag(D)</code></pre></td>
  100. <td><pre><code>igl::diag(D,M)</code></pre></td>
  101. <td>Construct new square matrix M with entries of vector D along the
  102. diagonal. Currently igl version supports sparse only.</td>
  103. </tr>
  104. <!-- Insert rows for each command pair -->
  105. <!-- Leave this here for copy and pasting
  106. <tr class=d0>
  107. <td><pre><code>Matlab code</code></pre></td>
  108. <td><pre><code>Eigen code</code></pre></td>
  109. <td>Notes</td>
  110. </tr>
  111. -->
  112. </table>
  113. </body>
  114. </html>