LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to find the mean of rows and columns matrix

Solved!
Go to solution

Here you go.

Thanks
uday
0 Kudos
Message 11 of 16
(1,885 Views)

sorry but i want to calculate the center mass of the matrix for element '1'

0 Kudos
Message 12 of 16
(1,877 Views)
Solution
Accepted by andisheye20

Did you enter 1 in element?

Thanks
uday
0 Kudos
Message 13 of 16
(1,876 Views)

This code should work:

 

The result is 0-indexed, so change it if you need to.

 

How it works:

 

1. Read in the sample array

2. Loop through every row, and pass the current row index into another for loop, call this i

3. Loop through every column of the current row, the index is j.

4. If the element at i, j is equal to the search element, index it out using a conditional indexing tunnel.

5. Concatenate all indexed tunnels, which essentially builds a master list of all the rows/columns where we found the search element

6. Calculate the mean index for both.

 

I got a mean row of 3.17, mean column of 4.52

0 Kudos
Message 14 of 16
(1,863 Views)

For the centre of mass you need to consider only those elements that are '1'.

So take the coordinates of all of those '1' elements, and calculate the mean of the 'x' and 'y' coordinates.

 

As an exercise for yourself, try recreating this:

centreofmass.JPG

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 15 of 16
(1,846 Views)

...and if Altenbach were online he would probably suggest using complex numbers:

centreofmasscomplex.JPG

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 16 of 16
(1,841 Views)