LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate maximum value of subarray while creating it using a case structure and shift registers

Solved!
Go to solution

I have two 1D arrays that contain cyclical information (kind of like a sine wave).  One that contains information on position in degrees and another that contains torque.  I would like to calculate the maximum torque value each time the position is within a certain range (e.g. from 30-80 degrees).  The ranges are repeated - that's why it is cyclical.   I use the "in range" function, a case structure and shift registers to build a new array with values that fall within the range I specify - this was the easy part (see VI attached).  I'm struggling with a way to calculate a maximum value for each subarray formed when values are "in range".   Your help is much appreciated.

0 Kudos
Message 1 of 11
(3,576 Views)

One way would be to keep track of the array indices when coming in/out of range.  Then, look at each one of those subsets and find the max value.

 

 

>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 2 of 11
(3,571 Views)

Something like this:  (Though, I'm sure there is a more elegant way)

 

max values.png

>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 3 of 11
(3,569 Views)

I thought of that and can easily create another array with indicies that fall within range.  However, I could only generate a list of indicies and I'm not sure where they should start and stop to use in an index array or array subset.  I might be able to figure it out if I knew when the case was true the first time it was in range.  

0 Kudos
Message 4 of 11
(3,566 Views)

I just got your last post - I'll check it and see if it work.  Thanks a bunch.  

0 Kudos
Message 5 of 11
(3,562 Views)

Is the position array really this regular? You then could just reshape the torque array into a 2D array, one cycle per row and then autoindex, taking the subset max for each iteration.

0 Kudos
Message 6 of 11
(3,554 Views)

Unfortunately, it's really not that regular where I could rely on it with confidence.  

0 Kudos
Message 7 of 11
(3,550 Views)
Solution
Accepted by topic author tmanini

vt92's solution worked!  I agree that there should be a simpler solution, but your's works just fine.  Many thanks.

 

0 Kudos
Message 8 of 11
(3,544 Views)

Then please attach more typical data. Is there noise in the real position?

0 Kudos
Message 9 of 11
(3,541 Views)

It's not really noise - it's more inconsistency.  So a position output can run: 20, 30, 40, 50, 60 etc.  OR, it could run: 21, 24, 32, 41, 44, 51, 59 etc. But, it is always cyclical. 

 

Attached you will find a .csv file with the data arrays - I'm using POS (ANAT) degrees column (column D if you open in excel).  There you also see torque in ft-lbs along with some other information.

 

 

0 Kudos
Message 10 of 11
(3,537 Views)