Main Content

Process Logged Sensor Data

This example shows how to plot orientation data acquired from a mobile device. 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 mobile device and connected it to the MathWorks Cloud. For information about these steps, see Install MATLAB Mobile on Your Device and Sign In to the Cloud.

  1. Start MATLAB Mobile on your mobile device.

  2. Sign in to the Cloud, if prompted.

  3. On the Sensors screen, tap the Orientation sensor.

  4. In the sensor settings, tap Stream to and then select MATLAB.

  5. Place the device where you want it for sending the sensor data.

  6. In MATLAB, create a mobiledev object, m.

    m = mobiledev
    m = 
    mobiledev with properties:
    
                       Connected: 1
               Available Cameras: {'back' 'front'}
                         Logging: 0
                InitialTimestamp: ''
    
       AccelerationSensorEnabled: 0
    AngularVelocitySensorEnabled: 0
           MagneticSensorEnabled: 0
        OrientationSensorEnabled: 1
           PositionSensorEnabled: 0
                                                                    
    Supported functions

    In the display that is shown when you create the object, a value of 1 indicates enabled or on, and 0 indicates not enabled or off. In this example, you can see that the device and Cloud are connected, and data is not being logged yet. The Orientation sensor is shown as enabled since you selected it on the device.

  7. Begin logging data from the selected sensor by setting the Logging property.

    m.Logging = 1

    This action starts the transmission of data from all selected sensors. You can also start transmission by tapping the Start button in MATLAB Mobile on the device.

  8. 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.

    disp(m)
    mobiledev with properties:
    
                       Connected: 1
               Available Cameras: {'back' 'front'}
                         Logging: 1
                InitialTimestamp: '06-08-2014 13:45:56.529'
    
       AccelerationSensorEnabled: 0
    AngularVelocitySensorEnabled: 0
           MagneticSensorEnabled: 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 see that the device and Cloud are connected, and data is being logged. The InitialTimestamp value shows the timestamp when the first packet of data was logged. The sensor values are displayed, indicating the current measurement values.

  9. After you have collected the quantity of data you need, stop logging sensor data.

    m.Logging = 0
  10. 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 data

    magfieldlog — Logged magnetic field data

    orientlog — Logged orientation data

    poslog — Logged position data, including data points for latitude, longitude, speed, course, altitude, and horizontal accuracy.

    See Device Orientation for a diagram showing the X, Y, and Z axes relative to the device.

    To get the logged orientation data from object m, assign the variable o for the logged orientation data and t for the timestamps.

    [o, t] = orientlog(m);

    You can then plot the data.

    plot(t, o) 

    Data plotted in MATLAB

    In this example, the Orientation data is from the device being moved a short distance for a few minutes. The plot shows the orientation (o) against time (t).

  11. You can keep the logs to access the data again, or discard them from your MATLAB session:

    discardlogs(m)
  12. When you are done with the session, delete the object.

    clear m

Related Topics