06-17-2009 01:47 AM
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
06-18-2009 04:23 PM
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.
06-18-2009 05:34 PM
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
06-19-2009 07:19 PM
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