Assume you have formatted data in a large text file or string, e.g.
Data,2015-09-16,15:41:52;781,780.000000,0.0034,2.2345
Data,2015-09-16,15:41:52;791,790.000000,0.1255,96.5948
Data,2015-09-16,15:41:52;801,800.000000,1.5123,0.0043
one may use textscan
to read this quite fast. To do so, get a file identifier of the text file with fopen
:
fid = fopen('path/to/myfile');
Assume for the data in this example, we want to ignore the first column "Data", read the date and time as strings, and read the rest of the columns as doubles, i.e.
Data , 2015-09-16 , 15:41:52;801 , 800.000000 , 1.5123 , 0.0043
ignore string string double double double
To do this, call:
data = textscan(fid,'%*s %s %s %f %f %f','Delimiter',',');
The asterisk in %*s
means "ignore this column". %s
means "interpret as a string". %f
means "interpret as doubles (floats)". Finally, 'Delimiter',','
states that all commas should be interpreted as the delimiter between each column.
To sum up:
fid = fopen('path/to/myfile');
data = textscan(fid,'%*s %s %s %f %f %f','Delimiter',',');
data
now contains a cell array with each column in a cell.