textscan string reading data as string

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Titus Edelhofer
Titus Edelhofer il 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 Commenti
Steven Reuter
Steven Reuter il 9 Feb 2016
Thanks for the response! Works great!!
Stephen23
Stephen23 il 9 Feb 2016
Modificato: Stephen23 il 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',',')

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Large Files and Big Data in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by