textscan string reading data as string

조회 수: 2 (최근 30일)
Steven Reuter
Steven Reuter 2016년 2월 9일
편집: Stephen23 2016년 2월 9일
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
Steven Reuter
Steven Reuter 2016년 2월 9일
Thanks for the response! Works great!!
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