Stream Sensor Data with Sensor Controls

Send sensor data to MATLAB® running on MathWorks® Cloud using MATLAB Mobile™ sensor controls. To communicate with the iOS device and acquire data from the sensors, you will create the mobiledev object as part of this procedure. You cannot log the sensor data until you create the object.

  1. Connect to the MathWorks Cloud in Settings .

    1. In MATLAB Mobile on your device, go to Settings > Connect to MathWorks Cloud.

    2. If you have previously connected from MATLAB Mobile:

      1. Tap your user ID.

      2. Tap Connect.

    3. If you have not previously connected from MATLAB Mobile:

      1. Tap Log In.

      2. Sign in to your MathWorks Account when prompted.

  2. In MATLAB Mobile, create a mobiledev object in MATLAB; for example:

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

    In the display that is shown when you create the object:

    • 0 - Not enabled, off, or the sensor is not available on this device.

    • 1 - Enabled or on.

    In this example, you can see that the device and the mobiledev object are connected, but the sensors are not enabled (all sensor values are 0) and data has not been logged yet (InitialTimestamp property is empty). If your device does not have a particular sensor, that sensor always shows a 0 in the display.

    InitialTimestamp is the timestamp of the first data point received by mobiledev. All other timestamps for all sensors are relative to InitialTimestamp.

  3. Tap the menu icon and then tap Sensors.

  4. Tap the icon for the sensor you want to turn on.

    If you are using the position sensor, turn on Location access for MATLAB in Settings on your device.

  5. If not already selected, tap Stream to MATLAB.

  6. To start sending data to MATLAB, tap START.

  7. At the MATLAB command line, view sensor data using the mobiledev object; for example:

    Current Sensor Values:
                    Acceleration: [-0.7200 4.6491 8.3620] (m/s^2)
  8. To stop sending data, tap STOP.

Repeat these steps to collect more data.

You can query latest values and plot the data or do other post-processing tasks. For examples, see Sensor Data Streaming Demo (MATLAB Mobile for iOS) and Use Logged Sensor Data Example (MATLAB Mobile for iOS).


If you are using Wi-Fi® as your connection method, you may have to adjust the sleep setting on your iOS device.

Related Topics