textscan string reading data as string

1 次查看(过去 30 天)
Hello, I am trying to read this date from a .dat file. I would like to read the final column as a single string. currently it only takes the first word. (disregaurd the for loop)
F =char(FileNames(n))
fileID = fopen(F)
if fileID == -1
else
C = textscan(fileID,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%s')
fclose(fileID);
Data
255.074738,252.110291,5.004000,2.632676,2.558489,0.378660,260.000000,250.000000,3.100000,2.160000,0.810000,0.200000,High Force Failure
255.005234,253.125081,5.004000,2.650853,2.573945,0.423147,260.000000,250.000000,3.100000,2.160000,0.810000,0.200000,High Force Failure
255.394465,253.156362,5.004000,2.670732,2.606145,0.441451,0.000000,-5.000000,10.000000,-1.000000,0.000000,0.000000,High Force Failure

采纳的回答

Titus Edelhofer
Titus Edelhofer 2016-2-9
Hi,
you need to tell textscan, that a space (" ") doesn't split strings. Add this to the call of textscan:
C = textscan(fileID,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%s', 'delimiter', '\n')
This says that only read new data again after a new line (and not start after the first word of the string at the end).
Titus
  2 个评论
Stephen23
Stephen23 2016-2-9
编辑:Stephen23 2016-2-9
Why not just use the delimiter option properly?:
C = textscan(fileID,'%f%f%f%f%f%f%f%f%f%f%f%f%s', 'delimiter',',')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by