This example shows how to plot orientation data. You can use the logged sensor data either during or after acquisition for plotting and other analyses.
This example assumes that you have already installed and set up MATLAB® Mobile™ on your Android™ device and connected it to your computer running MATLAB or the MathWorks Cloud. For information about these steps, see Get Started with Android Sensors.
Start MATLAB Mobile on your Android device.
On the Sensors screen of MATLAB Mobile, tap the Orientation sensor.
Place the device where you want it for sending the sensor data, if a remote location.
On your computer, in MATLAB, connect to the device if you are not already connected.
Alternatively, if you are running MATLAB using MathWorks Cloud, log in to the Cloud.
In MATLAB, create a
m = mobiledev
mobiledev with properties: Connected: 1 Logging: 0 InitialTimestamp: '' AccelerationSensorEnabled: 0 AngularVelocitySensorEnabled: 0 MagneticFieldSensorEnabled: 0 OrientationSensorEnabled: 1 PositionSensorEnabled: 0 Supported functions
In the display that is shown when you create the object, a value
1 means enabled or on, and
not enabled or off. In this example, you can see that the device and
computer are connected, and data is not being logged yet. The Orientation
sensor is shown as enabled since you selected it on the device.
Begin logging data from the selected sensor by enabling
m.Logging = 1
This action starts the transmitting of data from all selected sensors. You can also start transmission by tapping the Start button in MATLAB Mobile on the device.
You can see a display of the object properties any
time, using the
disp function. Now that you have
started logging data, the display shows more information.
mobiledev with properties: Connected: 1 Logging: 1 InitialTimestamp: '06-08-2014 13:45:56.529' AccelerationSensorEnabled: 0 AngularVelocitySensorEnabled: 0 MagneticFieldSensorEnabled: 0 OrientationSensorEnabled: 1 PositionSensorEnabled: 0 Current Sensor Values: Acceleration: [0x3 double] (m/s^2) AngularVelocity: [0x3 double] (rad/s) MagneticField: [0x3 double] (microtesla) Orientation: [1.8102 0.0101 -0.0418] (degrees) Position Data: Latitude: [0x1 double] (degrees) Longitude: [0x1 double] (degrees) Speed: [0x1 double] (m/s) Course: [0x1 double] (degrees) Altitude: [0x1 double] (m) HorizontalAccuracy: [0x1 double] (m) Supported functions
In the display, you can now see that the device and computer
are connected, and data is being logged. The
shows the timestamp when the first packet of data was logged. The
sensor values are displayed, indicating the current measurement value.
After you have collected the amount of data you need, stop logging sensor data.
m.Logging = 0
You can see the entire log of all readings using the log functions. You can use these functions while you are still logging, or after you stop. Each sensor type has a log function:
accellog — logged acceleration data
angvellog — logged angular velocity
magfieldlog — logged magnetic field
orientlog — logged orientation data
poslog — logged position data, including
data points for latitude, longitude, speed, course, altitude, and
See Device Orientation for a diagram showing the
Z axes relative to the device.
To get the logged orientation data from object
assign the variable
o for the logged orientation
t for the timestamps.
[o, t] = orientlog(m);
You can then plot the data.
In this example, the Orientation data is from the device being
moved a short distance for a few minutes. The plot shows the time
t) against orientation (
You can keep the logs to access the data again, or discard them. To discard all logs from your MATLAB session:
When you are done with the session, delete the object.
Close the connection between MATLAB and the Android device.