You are on page 1of 3

Table of Contents

Import data from text file. .................................................................................................... 1


Initialize variables. .............................................................................................................. 1
Format string for each line of text: ........................................................................................ 1
Open the text file. .............................................................................................................. 2
Read columns of data according to format string. ..................................................................... 2
Close the text file. .............................................................................................................. 2
Post processing for unimportable data. ................................................................................... 2
Allocate imported array to column variable names ................................................................... 2
Clear temporary variables .................................................................................................... 3

Import data from text file.


Script for importing data from the following text file:

E:\Education\KPIT course
certificates\Sensor_record_20200506_183136_AndroSensor.csv

To extend the code to different selected data or a different text file, generate a function instead of a script.

% Auto-generated by MATLAB on 2020/05/06 18:39:40

Initialize variables.
filename = 'E:\Education\KPIT course certificates\Sensor_record_20200506_183136_And
delimiter = ';';
startRow = 3;

Format string for each line of text:


column1: double (%f)

% column2: double (%f)


% column3: double (%f)
% column4: double (%f)
% column5: double (%f)
% column6: double (%f)
% column7: double (%f)
% column8: double (%f)
% column9: double (%f)
% column10: double (%f)
% column11: double (%f)
% column12: double (%f)
% column13: double (%f)
% column14: double (%f)
% column15: double (%f)
% column16: double (%f)
% column17: double (%f)
% column18: double (%f)

1
% column19: double (%f)
% column20: double (%f)
% column21: double (%f)
% column22: double (%f)
% column23: double (%f)
% column24: text (%s)
% column25: text (%s)
% column26: text (%s)
% column27: double (%f)
% column28: text (%s)
% column29: text (%s)
% column30: double (%f)
% column31: text (%s)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%s%s%s%f%s%s%f%s%[^\n\r

Open the text file.


fileID = fopen(filename,'r');

Read columns of data according to format


string.
This call is based on the structure of the file used to generate this code. If an error occurs for a different
file, try regenerating the code from the Import Tool.

dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,sta

Close the text file.


fclose(fileID);

Post processing for unimportable data.


No unimportable data rules were applied during the import, so no post processing code is included. To
generate code which works for unimportable data, select unimportable cells in a file and regenerate the
script.

Allocate imported array to column variable


names
ACCELEROMETERXms = dataArray{:, 1};
ACCELEROMETERYms = dataArray{:, 2};
ACCELEROMETERZms = dataArray{:, 3};
GRAVITYXms = dataArray{:, 4};
GRAVITYYms = dataArray{:, 5};
GRAVITYZms = dataArray{:, 6};
LINEARACCELERATIONXms = dataArray{:, 7};

2
LINEARACCELERATIONYms = dataArray{:, 8};
LINEARACCELERATIONZms = dataArray{:, 9};
GYROSCOPEXrads = dataArray{:, 10};
GYROSCOPEYrads = dataArray{:, 11};
GYROSCOPEZrads = dataArray{:, 12};
LIGHTlux = dataArray{:, 13};
MAGNETICFIELDXT = dataArray{:, 14};
MAGNETICFIELDYT = dataArray{:, 15};
MAGNETICFIELDZT = dataArray{:, 16};
ORIENTATIONZazimuth = dataArray{:, 17};
ORIENTATIONXpitch = dataArray{:, 18};
ORIENTATIONYroll = dataArray{:, 19};
PROXIMITYi = dataArray{:, 20};
SOUNDLEVELdB = dataArray{:, 21};
LOCATIONLatitude = dataArray{:, 22};
LOCATIONLongitude = dataArray{:, 23};
LOCATIONAltitudem = dataArray{:, 24};
LOCATIONAltitudegooglem = dataArray{:, 25};
LOCATIONSpeedKmh = dataArray{:, 26};
LOCATIONAccuracym = dataArray{:, 27};
LOCATIONORIENTATION = dataArray{:, 28};
Satellitesinrange = dataArray{:, 29};
Timesincestartinms = dataArray{:, 30};
YYYYMODDHHMISS_SSS = dataArray{:, 31};

Clear temporary variables


clearvars filename delimiter startRow formatSpec fileID dataArray ans;

Published with MATLAB® R2013a

You might also like