Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

elements in a matrix

Hi,

I have a matrix A=[2 1 -1;-1 5 -2;-2 -4 -5;1 2 3], and I would like to determine the every element in A. If the element is 

 

greater or equal to zero, I will change the element to 1. Otherwise, the element is changed by -1. In other words, the new matrix should be B=[1 1 -1;-1 1 -1;-1 -1 -1;1 1 1] based on the rules before. Does anyone help me?

 

Thanks,

 

POPo

0 Kudos
Message 1 of 4
(6,406 Views)

Hi PoPo, I assume you want to know for C++, since you've posted on the Measurement Studio Visual C++ board.  This code should do the trick:

 

myArray = {{2, 1, -1}, {-1, 5, -2}, {-2, -4, -5} {1, 2, 3} }; m=4; n=3; for (int i = 0; i <m; i++) { for (int j = 0; j<n; j++) if (myArray[i][j] >= 0) myArray[i][j] = 1; else myArray[i][j] = -1; } }

 

 

For general/non-NI programming questions like this, there are extensive amounts of information on the internet. A Google search for "2D Array C++"is a great place to start.


Mark E.
National Instruments

0 Kudos
Message 2 of 4
(6,373 Views)

Hi Mark,

 

   Thank you for your information. However, I would like to implement this idea in LabVIEW. How can I change the elements in a matrix,especially the size of matrix is big? 

 

Thank you,

 

POPO

0 Kudos
Message 3 of 4
(6,369 Views)

Hi POPO,

You'll want to post your LabVIEW questions on the LabVIEW forums for effective support.  That way it will also be found most easily by other LabVIEW users.  This is the forum for Measurement Studio for VC++. You can find the LabVIEW forum at http://forums.ni.com

 


Mark E.
National Instruments

0 Kudos
Message 4 of 4
(6,335 Views)