tomstewart89 / BasicLinearAlgebra

A library for using matrices and linear algebra on Arduino
MIT License
187 stars 38 forks source link

Access specific row/col? #29

Closed Nate711 closed 3 years ago

Nate711 commented 3 years ago

Is there a way to get a specific row or column from a matrix? Perhaps as a reference matrix?

thomascent commented 3 years ago

Hey @Nate711, yep as you guessed you can do this using a reference matrix, or even just the convenience method of the Matrix class Submatrix which will create a reference matrix given some row/col ranges. Something this should do the trick:

using namespace BLA;

Matrix<4,4> A;
auto second_row_of_A = A.Submatrix(Slice<1,0>(), Slice<0,4>());
auto third_col_of_A = A.Submatrix(Slice<0,8>(), Slice<2,3>());

You might have seen it already but there's an example sketch for using reference matrices in the examples folder, that goes into a bit more detail about them.

Hope that helps, let me know if you have any trouble!