textscan string reading data as string

2 Ansichten (letzte 30 Tage)
Steven Reuter
Steven Reuter am 9 Feb. 2016
Bearbeitet: Stephen23 am 9 Feb. 2016
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

Akzeptierte Antwort

Titus Edelhofer
Titus Edelhofer am 9 Feb. 2016
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 Kommentare
Steven Reuter
Steven Reuter am 9 Feb. 2016
Thanks for the response! Works great!!
Stephen23
Stephen23 am 9 Feb. 2016
Bearbeitet: Stephen23 am 9 Feb. 2016
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',',')

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by