Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

how do I make a matrix of vector

I am trying to make a matrix of CNiReal32Vector. How should I declare the variable and how should I index it?
Now I have (I simplify it to make it easy to understand)
CNiReal32Vector* MyMatrix;
CNiReal32Vector MyVector;
int xSize = 5, ySize = 10;
MyMatrix.SetSize(xSize*ySize
MyMatrix[2][3] = MyVector; //Here I got an error saying binary "=" does not take CNiReal32Vector type.
0 Kudos
Message 1 of 7
(5,573 Views)
Hi,

The CNiReal32Vector will only accept 32-bit reals as values. So when you declare MyMatrix, it is only allowing reals to be defined here, not pointers to Vectors.

You will have to do something like:

CNIReal32Vector MyMatrix[10][5];
CNiReal32Vector MyVector;
MyMatrix[2][3] = MyVector;

Hope this helps!

Allen P.
National Instruments
Message 2 of 7
(5,572 Views)
You could also use the CNiReal32Matrix datatype which is a built in matrix data type. You can build up a matrix using pre-existing cnivectors as well. The Measurement Studio documentation has more information about this data type.

Hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 3 of 7
(5,572 Views)
I am currently having component works version 1. I did see CNiRealVectorT, but it doesn't have any example to that. Do you have a document that explains and gives the example of how to use the dataType?
Thanks
0 Kudos
Message 4 of 7
(5,572 Views)
The CVIRealVector class is a templatized class which defines vectors for data types from unsigned 8 bit to 64 bit floating point types. I dont have componentworks 1.0 , the current version is Measurement studio (formerly known as componentworks) 7.1, so I dont know what the documentation looks like

But here is a way to create a matrix from a couple of vectors

double doubleData[256];
for(int i=0;i<256;i++)
doubleData[i] = i;


CNiReal32Vector vectorData(256,doubleData);

for(int i=0;i<256;i++)
doubleData[i] = 2.0*i;

//Copies doubleData buffer to create another vector
CNiReal32Vector anotherVectorData(256,doubleData);

//2 rows, 256 columns
CNiReal32Matrix dataMatrix(2,256);

/
/Copies vector data into matrix.
dataMatrix.AssignRow(0,vectorData);
dataMatrix.AssignRow(1,anotherVectorData);

The help for the CNiRealVectorT class should define all the basic methods for the template class. ANd since this is a template, you have access to the source of the vector class.

The shipping examples use the vector classes, you should check those out to see if they help.

Could you clarify what you are trying to do?

You should even consider upgrading, since we have made ALOT of improvements since the 1.0 version in terms of bug fixes, functionality, documentation etc. MStdio 7.1 now provides .NET support as well as support for Visual Studio .NET 2003.

Bilal Durrani
NI
Bilal Durrani
NI
Message 5 of 7
(5,572 Views)

I am using Measurement Studio and MS VS 2003 C++ and MFC (not managed).

My app requires that I process multiple sequences of data, accumulate the sequences as vectors in a matrix, then chart each of the vectors. Each sequence is added to a CNiReal64Vector. Then each vector is assigned to a  row in a CNiReal64Matrix.  I have to do it this way since each run has an unknown variable number of vectors, so everything is done in loops.

Once I have made a matrix of vectors, how do I refer to each of them when I want to plot the vectors using PlotXvsY for example. The compiler complains when I try to refer to the data in the matrix in a variety of the seemingly obvious ways.

CNiReal64Matrix  mvx(10,10000);
CNiReal64Matrix  mvy(10,10000);

CNiReal64Vector  vx;
CNiReal64Vector  vy;

in a loop data points are added:
    vx.Append(some double value);
    vy.Append(some double value);

Then, vectors are assigned to the matrix:
   mvx.AssignRow(rownum, vx);
   mvy.AssignRow(rownum, vy);

   vy.SetSize(0);
   vx.SetSize(0);

...and repeat the loop above for next vector....

...later I need to plot each vector in the matrix...

    m_Graph.Plots.Item(plotnum).PlotXvsY(mvx[plotnum], mvy[plotnum]);

....and it is not obvious at this point how to access/refer to a vector in the matrix???

Any help would be appreciated.

Thanks
MikeeyG

 

0 Kudos
Message 6 of 7
(5,194 Views)
MikeeyG:

The direct answer to your question is as follows:

(1) You can't use the bracket ([]) operator on a CNiMatrix type. Though this works on the vector, C++ requires the bracket operator to have only one parameter, so we used the function call operator (parentheses) on the matrix instead. For example:
    CNiReal64Vector v(30,3.14);  // vec with 30 elements, all set to 3.14
    CNiReal64Matrix m(2,3,3.14); // 2 x 3 matrix with all elements set to 3.14

    double d = v[0];             // Access first element
    double e = m(0,0);           // Access 'first' element
(2) If you want to get a certain column or row of a matrix into a vector, you can use the CNiMatrixT<>::CopyColumn or CNiMatrixT<>::CopyRow method. For example:
    CNiReal64Matrix m(2,3,3.14); // 2 x 3 matrix with all elements set to 3.14

    CNiReal64Vector v;           // empty vector
    m.CopyRow(0,v);
    // v now has a copy of row 0
Note that this method is making a copy of the matrix's data, rather than pointing to it or referencing it.

Finally, I noticed that CNiGraph has a PlotXvsY method that takes a CNiMatrix directly, which may be easier for you to use.

-- Chris
NI
Message 7 of 7
(5,161 Views)