mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-23 14:53:13 +08:00
Mention comma initializer can be used to concatenate vectors
(inspired by a question on IRC)
This commit is contained in:
parent
1a6597b8e4
commit
8bca23bbec
@ -32,20 +32,20 @@ or too many coefficients, Eigen will complain.
|
|||||||
\verbinclude Tutorial_commainit_01.out
|
\verbinclude Tutorial_commainit_01.out
|
||||||
</td></tr></table>
|
</td></tr></table>
|
||||||
|
|
||||||
The comma initializer can also be used to fill block expressions such as <tt>m.row(i)</tt>. Here is a more
|
Moreover, the elements of the initialization list may themselves be vectors or matrices. A common use is
|
||||||
complicated way to get the same result as above:
|
to join vectors or matrices together. For example, here is how to join two row vectors together. Remember
|
||||||
|
that you have to set the size before you can use the comma initializer.
|
||||||
|
|
||||||
<table class="example">
|
<table class="example">
|
||||||
<tr><th>Example:</th><th>Output:</th></tr>
|
<tr><th>Example:</th><th>Output:</th></tr>
|
||||||
<tr><td>
|
<tr><td>
|
||||||
\include Tutorial_commainit_01b.cpp
|
\include Tutorial_AdvancedInitialization_Join.cpp
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
\verbinclude Tutorial_commainit_01b.out
|
\verbinclude Tutorial_AdvancedInitialization_Join.out
|
||||||
</td></tr></table>
|
</td></tr></table>
|
||||||
|
|
||||||
Moreover, the elements of the initialization list may themselves be matrices. Thus, we can use them to
|
We can use the same technique to initialize matrices with a block structure.
|
||||||
initialize matrices with a block structure.
|
|
||||||
|
|
||||||
<table class="example">
|
<table class="example">
|
||||||
<tr><th>Example:</th><th>Output:</th></tr>
|
<tr><th>Example:</th><th>Output:</th></tr>
|
||||||
@ -56,6 +56,18 @@ initialize matrices with a block structure.
|
|||||||
\verbinclude Tutorial_AdvancedInitialization_Block.out
|
\verbinclude Tutorial_AdvancedInitialization_Block.out
|
||||||
</td></tr></table>
|
</td></tr></table>
|
||||||
|
|
||||||
|
The comma initializer can also be used to fill block expressions such as <tt>m.row(i)</tt>. Here is a more
|
||||||
|
complicated way to get the same result as in the first example above:
|
||||||
|
|
||||||
|
<table class="example">
|
||||||
|
<tr><th>Example:</th><th>Output:</th></tr>
|
||||||
|
<tr><td>
|
||||||
|
\include Tutorial_commainit_01b.cpp
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
\verbinclude Tutorial_commainit_01b.out
|
||||||
|
</td></tr></table>
|
||||||
|
|
||||||
|
|
||||||
\section TutorialAdvancedInitializationSpecialMatrices Special matrices and arrays
|
\section TutorialAdvancedInitializationSpecialMatrices Special matrices and arrays
|
||||||
|
|
||||||
|
11
doc/snippets/Tutorial_AdvancedInitialization_Join.cpp
Normal file
11
doc/snippets/Tutorial_AdvancedInitialization_Join.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
RowVectorXd vec1(3);
|
||||||
|
vec1 << 1, 2, 3;
|
||||||
|
std::cout << "vec1 = " << vec1 << std::endl;
|
||||||
|
|
||||||
|
RowVectorXd vec2(4);
|
||||||
|
vec2 << 1, 4, 9, 16;;
|
||||||
|
std::cout << "vec2 = " << vec2 << std::endl;
|
||||||
|
|
||||||
|
RowVectorXd joined(7);
|
||||||
|
joined << vec1, vec2;
|
||||||
|
std::cout << "joined = " << joined << std::endl;
|
Loading…
x
Reference in New Issue
Block a user