Identify position based on voltage data

artz

Well-known Member
Joined
Aug 11, 2002
Messages
830
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I am using an accelerometer to determine a patient's position on a bed. Five positions need to be identified. In the table below, corresponding accelerometer voltages were measured in each of the five positions.

Code:
Orientation	Vx	Vy	Vz
Supine flat	1.666	1.68	1.007
Supine 10˚	1.657	1.88	1.036
Prone     	1.656	1.681	2.34
Left side	1.671	1.009	1.615
Right side	1.687	2.325	1.675


Can anyone in the Forum identify the logic needed where the inputs would be Vx, Vy, and Vz and the ouput would be position?

A nested if statement would seem to be the way to do this or with VBA. Any help is greatly appreciated.

Thanks,

Art
 
Hi kweaver,

The data are part of a study looking at sleeper position over the course of a sleep night. Accelerometer data are digitized by an Adafruit DAQ for next day analysis. Only the five positions described are being considered.

You used a 2% window; this could probably be an input variable. Also, positions returning voltages outside the values described could return, "No Position". This could change, but for now, starting with the nominal voltages and a tolerance that can be varied should suffice.

So, yes, each row of Vx, Vy, and Vz would be tested for the criteria and a value for position would be returned with the "No Position" value returned as described as above.

Does this help to explain what I need? Certainly a VBA solution seems preferable.

Thanks,

Art
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Not really. I guess I'm being somewhat dense here. Correct me, of course, if I'm wrong...
But, are you saying that there would be SEVERAL triples on the input side, each of which would show a position?
 
Upvote 0
Will this adjustment do it?


Excel 2010
ABCDE
1OrientatonVxVyVz
2Supine flat1.6661.681.007
3Supine 10"1.6571.881.036
4Prone1.6561.6812.34
5Left side1.6711.0091.615
6Right side1.6872.3251.675
7Tollerance2%Position
8Input:1.682.31.69Right side
91.6551.891.035Supine 10"
10
11
12
13
14
15
VoltageData
Cell Formulas
RangeFormula
E8{=IF(ISBLANK(B8),"",IFERROR(INDEX($A$2:$A$6,MATCH(1,($B$2:$B$6<=B8*(1+$B$7))*($B$2:$B$6>=B8*(1-$B$7))*($C$2:$C$6<=C8*(1+$B$7))*($C$2:$C$6>=C8*(1-$B$7))*($D$2:$D$6<=D8*(1+$B$7))*($D$2:$D$6>=D8*(1-$B$7)),0),1),0))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Hi kweaver,

The input (this is just to ID inputs/outputs, not in actual worksheet)

This is an abbreviated data table that would returned in the data acquisition file. The output column would be returned when the input columns are processed in Excel.

Can you come up with some code to process the input data? I think this would require VBA, but I don't know.

Thanks,

Art

Code:
Input	Input	Input	Input	Output
Time	Vx	Vy	Vz	Orientation
0	1.666	1.68	1.007	Supine flat
1	1.666	1.68	1.007	Supine flat
2	1.666	1.68	1.007	Supine flat
3	1.666	1.68	1.007	Supine flat
4	1.666	1.68	1.007	Supine flat
5	1.666	1.68	1.007	Supine flat
6	1.657	1.88	1.036	Supine 10˚
7	1.657	1.88	1.036	Supine 10˚
8	1.657	1.88	1.036	Supine 10˚
9	1.657	1.88	1.036	Supine 10˚
10	1.657	1.88	1.036	Supine 10˚
11	1.657	1.88	1.036	Supine 10˚
12	1.657	1.88	1.036	Supine 10˚
13	1.657	1.88	1.036	Supine 10˚
14	1.656	1.681	2.34	Prone
15	1.656	1.681	2.34	Prone
16	1.656	1.681	2.34	Prone
17	1.656	1.681	2.34	Prone
18	1.671	1.009	1.615	Left
19	1.671	1.009	1.615	Left
20	1.671	1.009	1.615	Left
21	1.671	1.009	1.615	Left
22	1.671	1.009	1.615	Left
23	1.687	2.325	1.675	Right
24	1.687	2.325	1.675	Right
25	1.687	2.325	1.675	Right
26	1.687	2.325	1.675	Right
27	1.687	2.325	1.675	Right
28	1.687	2.325	1.675	Right
 
Upvote 0
I think my last example w/2% tolerance did it, yes/no?


Excel 2010
ABCDE
1OrientatonVxVyVz
2Supine flat1.6661.681.007
3Supine 10"1.6571.881.036
4Prone1.6561.6812.34
5Left side1.6711.0091.615
6Right side1.6872.3251.675
7Tollerance2%Position
8Input:1.6661.681.007Supine flat
91.6661.681.007Supine flat
101.6661.681.007Supine flat
111.6661.681.007Supine flat
121.6661.681.007Supine flat
131.6661.681.007Supine flat
141.6571.881.036Supine 10"
151.6571.881.036Supine 10"
161.6571.881.036Supine 10"
171.6571.881.036Supine 10"
181.6571.881.036Supine 10"
191.6571.881.036Supine 10"
201.6571.881.036Supine 10"
211.6571.881.036Supine 10"
221.6561.6812.34Prone
231.6561.6812.34Prone
241.6561.6812.34Prone
251.6561.6812.34Prone
261.6711.0091.61Left side
271.6711.0091.61Left side
281.6711.0091.61Left side
291.6711.0091.61Left side
301.6711.0091.61Left side
311.6872.3251.67Right side
321.6872.3251.67Right side
331.6872.3251.67Right side
341.6872.3251.67Right side
351.6872.3251.67Right side
VoltageData (2)
Cell Formulas
RangeFormula
E8{=IF(ISBLANK(B8),"",IFERROR(INDEX($A$2:$A$6,MATCH(1,($B$2:$B$6<=B8*(1+$B$7))*($B$2:$B$6>=B8*(1-$B$7))*($C$2:$C$6<=C8*(1+$B$7))*($C$2:$C$6>=C8*(1-$B$7))*($D$2:$D$6<=D8*(1+$B$7))*($D$2:$D$6>=D8*(1-$B$7)),0),1),0))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Hi kweaver,

Yes, your last formulary works great. Thanks! It appears that you are also handling blank cells- this is good. A few questions remain:

Can a similar formula be done without an array formula? Or can the array formula look for the last used row? With the array formula, I need to allocate at least or more rows that contain data. Also, array formulas can be finicky if you change something.

I mentioned in my last post returning a message in the corresponding row cell if the voltage values don't match the prescribed x, y, z value ranges.

Is there a way to address this?

Thanks,

Art
 
Upvote 0
I'm not sure why you don't feel right about the array formulas. I see no issue with them.
As for returning a message when there isn't a match: that can be done by changing E7 to the following, and filling down:

Code:
=IF(ISBLANK(B8),"",IFERROR(INDEX($A$2:$A$6,MATCH(1,($B$2:$B$6<=B8*(1+$B$7))*($B$2:$B$6>=B8*(1-$B$7))*($C$2:$C$6<=C8*(1+$B$7))*($C$2:$C$6>=C8*(1-$B$7))*($D$2:$D$6<=D8*(1+$B$7))*($D$2:$D$6>=D8*(1-$B$7)),0),1),"No Orientation"))
 
Upvote 0
Hi kweaver,

Thanks so much, your formula works great! :) The reason I generally don't like array formulas if that if you mess up part of the formula in a cell, you receive the message: "You can't change part of an array". The only way that I found to get out of that was to shutdown Excel from the Task Manager. So, that's my beef with array formulas.

So, now it's time to build some hardware, collect some data, and try out your formula.

Thanks again,

Art
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top