         gyroXText.text = "Gyro-X: 0.0"
         gyroYText.text = "Gyro-Y: 0.0"
         gyroZText.text = "Gyro-Z: 0.0"
-
+        columnNum = Int(dataLogTime/updateInterval)
+        dataMatrix = Array(repeating: Array(repeating:0.0, count: 4), count: columnNum)
+        
         if manager.isGyroAvailable && manager.isAccelerometerAvailable && manager.isDeviceMotionAvailable {
             //Set sensor data updates to 0.1 seconds
             manager.accelerometerUpdateInterval = updateInterval

    }
    
    func startLoggingData(){
        let columnNum = Int(dataLogTime/updateInterval)
        
        //Create an emtpy array to store the data
        var dataMatrix = Array(repeating: Array(repeating:0.0, count: 4), count: columnNum)
        
        //start accelerometer data and loop through the dataMatrix to store data
        manager.startAccelerometerUpdates(to: .main) {
            [weak self] (data: CMAccelerometerData?, error: Error?) in
            if (data?.acceleration) != nil {
                var dataInd = 0.0
                for i in 0..<columnNum{
                    dataMatrix[i][0] = dataInd
                    dataInd += (self?.updateInterval)!
                    dataMatrix[i][1] = (data?.acceleration.x)!
                    dataMatrix[i][2] = (data?.acceleration.y)!
                    dataMatrix[i][3] = (data?.acceleration.z)!
                }
                print(dataMatrix) //for testing only
            }
        }
        self.stopUpdates()
    }
    
    func stopUpdates(){
        manager.stopAccelerometerUpdates()
        manager.stopGyroUpdates()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.

        print("Stop Live Update Button Clicked!")
        self.stopUpdates()
    }
    // MARK: Main constants and vars
    let updateInterval = 0.1
    let dataLogTime = 10.0 //seconds
    var columnNum:Int = 0
    var timer = Timer()
    var counter = 0
    var i = 0
    var dataInd = 0.0
    var ax = 0.0
    var ay = 0.0
    var az = 0.0
    
    //Create an emtpy array to store the data
    var dataMatrix = [[Double]]()
    
    // MARK: init
    
    override func viewDidLoad() {
