How can I access a single vector from a matrix?
For example: Is there a way to extract a vector using something like A(i) for a matrix Eigen::MatrixXf A(10,10) that returns an Eigen::VectorXf A(10)?
Found in the documentation :/
The way to access a single column is .col(i), and similarly for row, its .row(i). Also of interest is .block<>.
Related
I can send the row of a matrix, and the column of another matrix in a single MPI_SEND, how can I do this procedure?
MPI_SEND (row and column of the matrix ...)
Since C/C++ works in row major order, you can either declare your 2D matrix in a 1D vector and access its entries by using a simple convention. Assuming A is of size mxn and B is a vector;
A[i][j] = B[i*n+j];
But if you are coding in C++, I would suggest defining a matrix object and try sending these objects in MPI. You would have to create your own MPI_Data_Type.
I am trying to make a WorldToView matrix and for that I need to calculate the right(r),up(u) and view vectors(v).
I know the eye vector is eye(0,0,0) and at vector is at(0,0,-1); then by:
v= normalise(at-eye); view vector v will be (0,0,-1)
How do I get r and u vectors?
I know that:
r=normalise(v X u);
u=normalise(r X v);
Thanks
You don't have enough information at the moment - you don't know which way up your viewer is oriented, it could be anything. You probably want to specify an up vector, e.g. (0,1,0), and then calculate r using the equation.
Note, for what it's worth, that gluLookAt, the GLU function that does the equivalent of what you're trying to do, takes three parameters, not two - namely an eye vector, an at vector and an up vector. You're missing the up vector, hence why you're running into difficulties.
I created a m-by-n matrix Mat and I would like to add a scalar to just one row of this matrix. In order to add a scalar to all elements of the matrix, you can use the following statement: A += b, where A is a Mat object and b in a scalar. But if I wanted to add a scalar to just one row of this matrix, how to perform this operation just as easily?
This is very easy:
image.row(i) += Scalar(...);
Taken from docs:
There are many different ways to create a Mat object. The most popular
options are listed below:
...
Construct a header for a part of another
array. It can be a single row, single column, several rows, several
columns, rectangular region in the array (called a minor in algebra)
or a diagonal. Such operations are also O(1) because the new header
references the same data. You can actually modify a part of the array
using this feature
...
A common thing to do in machine learning is to have the first column of a dataset represent the class that the corresponding row belongs to for a data point.
Basically, I have a cv::Mat and I want to efficiently create a cv::Mat containing that matrix with the first column removed. Is there a more efficient way of doing this than looping over the columns and rows and adding the elements one by one with mat.at<data_type>(row, col) = elem; ?
See Mat::operator() from OpenCV documentation.
I want to transform this data (I was told to do it from the object perspective). A list of the data is:
[0, -20.790001, -4.49] make up the acceleration xyz coordinates - accel(x,y,z).
[-0.762739, -3.364226, -8.962189] make up angle xyz coordinates - angle(x,y,z).
I am trying to use Rodrigues’ rotation formula or linear transformation matrix for rotation? Is this different with sensor data?
I am able to read the data from .csv, but am unsure how to transform into C++ and how to create a matrix in C++.
As long as you have a formula for transformation of the data, you just need to apply it. As for the matrix and creating one, there are multiple ways, either by using a double array:
float matrix[][] ( or matrix** if you want to use pointers )
or using a class (or struct, up to you) which contains the rows and columns
class Matrix
float rows[]
float columns[]
Good luck!
Note: just pseudo code definitely won't work out of the box, obviously