textscan string reading data as string

2 vues (au cours des 30 derniers jours)
Steven Reuter
Steven Reuter le 9 Fév 2016
Modifié(e) : Stephen23 le 9 Fév 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

Réponse acceptée

Titus Edelhofer
Titus Edelhofer le 9 Fév 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 commentaires
Steven Reuter
Steven Reuter le 9 Fév 2016
Thanks for the response! Works great!!
Stephen23
Stephen23 le 9 Fév 2016
Modifié(e) : Stephen23 le 9 Fév 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',',')

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by