LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

vector to matrix tranformation

Could someone help me in transforming a vector with 100 elements into a matrix, with 10 rows and 10 columns? Thank you verry much
0 Kudos
Message 1 of 13
(4,172 Views)

What exactly is the problem?

 

I would use two nested loops, with something like matrix [i][j] = vector [i*10+j]

Message Edited by Wolfgang on 06-11-2010 06:25 PM
0 Kudos
Message 2 of 13
(4,169 Views)

The probleme is that i want to transform  a vector with values from a table (100 values), into a 10 x10 matrix array, with the following code

 

 

 GetTableCellRangeVals (panelHandle, PANEL_TABLE, MakeRect(1,1,n,n), value_matrix, VAL_COLUMN_MAJOR);

for(i=1;i<=n-1; i++)                  
                          {for(j=1;j<=n-1; j++)                  
                                 value_matrix[i]==matrix_1[i][j];}

 

Transpose (matrice_valori, n, n, matrice_transpusa);
                      
                       for(i=1; i<=numar-1; i++)
                      
                       {for(j=1;j<=numar-1; j++)
                          if(matrice_1[i][j]>=0)
                          {if(matrice_1[i][j]==matrice_transpusa[i][j])

SetCtrlVal (panelHandle, PANEL_LED, 1); }

 

 

 Then I transpose the matrix, and compare it with the initial 10x10 matrix, and if all goes to plan. it should light up a LED.

 

But the probleme is that the vector does not copy itself into the matrix as it should, because my LED light up  all the time. I can't seem to find the bug in these lines of code

0 Kudos
Message 3 of 13
(4,167 Views)

I don't understand your code:

 


for(i=1;i<=n-1; i++)                  
                          {for(j=1;j<=n-1; j++)                  
                                 value_matrix[i]==matrix_1[i][j];}


 

 

1) why does the index start at 1, not at zero?

 

2) the GetTable function returns value_matrix, why do you set new values using value_matrix == ? If you want to define your matrix, you will need to write matrix_1 [][] = ...

 

3) The matrix should be 10x10, in your case the indices i and j will run to 100? 

0 Kudos
Message 4 of 13
(4,165 Views)

1. It starts at 1 because the table i get my data from starts from row 1 column 1.

 

2. It got mixed arround, in the program; it actually is" matrix_1==value_matrix[i]". For some strange reason, allthough I have  "Build with C99" turned on, i can't declare varible matrices ( matrix_1[n][m]), so the matrix is defined at it's maximum value  matrix_1[10][10];

 

3.No,  because the the table has  variable numbers of rows and columns, i and j  don't  get past 10.The minimun is 2 and the maximum 10.

 

 

0 Kudos
Message 5 of 13
(4,159 Views)

ok... So did you check, using the Variable window, that your manually filled matrix is indeed filled with data as you want it to be?

 

You are transpoing different matrices than you are comparing later on...

Message Edited by Wolfgang on 06-11-2010 07:05 PM
0 Kudos
Message 6 of 13
(4,157 Views)
The data is inputed correctly, and  the function Transpose is already in the program.
0 Kudos
Message 7 of 13
(4,152 Views)

I was asking for the correct matrix [][] because of your sentence

 


But the probleme is that the vector does not copy itself into the matrix as it should

 

For me this means that the matrix is not as it should... ?

 

So, may be you also check the transposed matrix manually: the LED might not work as expected, e.g. if your routine is in a callback and no draw events are processed;

0 Kudos
Message 8 of 13
(4,150 Views)

I've just noticed that this line of code is wrog, the one that  takes the vector and puts it into the matrix 

 

  for(i=1;i<=numar-1; i++)                  
               {for(j=1;j<=numar-1; j++)

matrix_1[i][j]==value_matrix[i];}

 

 For the matrix, it reads all the elements, but for the vector, only half of them.

 

So  back to my initial question.... how do you transform a  vector  into a matrix? in my case, a 100 value vector, into a 10x10 matrix.

0 Kudos
Message 9 of 13
(4,146 Views)

are you referring to the vector you decided to call value_matrix?

 

Sorry, but I am still confused:

 

when I was asking if you checked your matrix_1 you said that that the input is ok.

 

How can it be ok (you need 10x10 values) if you read in only half of your vector, i.e. 50 elements...? I am giving up...

 

 

0 Kudos
Message 10 of 13
(4,143 Views)