textscan only reads first row of text file

조회 수: 12 (최근 30일)
Simone Ricci
Simone Ricci 2021년 11월 7일
댓글: Simone Ricci 2021년 11월 7일
filename = 'Prova_1.txt';
fileID = fopen(filename,'r');
time = 'Time: %d ';
acceleration = 'G in body frame: %f ;%f ;%f ; ';
omega = 'Omega: %f ;%f ;%f ; ';
balane = 'r balane: %f ;%f ;%f ; ';
quaternion = 'quat: %f ;%f ;%f ; %f ; ';
magnetic = 'Mag: %f ;%f ;%f ; %f ;%f ;%f ;';
formatSpec = [time acceleration omega balane quaternion magnetic];
A = textscan(fileID,formatSpec);
fclose(fileID);
With the code included it only reads the first row of the text file. Can't find what's wrong or missing.

채택된 답변

Stephen23
Stephen23 2021년 11월 7일
편집: Stephen23 2021년 11월 7일
fmt = 'Time%dG in body frame%f%f%fOmega%f%f%fr balane%f%f%fquat%f%f%f%fMag%f%f%f%f%f%f%f';
opt = {'Delimiter',{';',':',' '}, 'MultipleDelimsAsOne',true, 'CollectOutput',true};
fid = fopen('Prova_1.txt','rt');
out = textscan(fid,fmt,opt{:});
fclose(fid);
ts = out{1}
ts = 1281×1
460977 461477 461978 462478 462979 463479 463980 464480 464981 465481
out = out{2}
out = 1281×20
-0.0387 0.0195 1.0046 0.0017 0.0041 0.0087 0 0 0 -0.0436 0.0190 -0.0103 -0.9988 0.0425 -0.0309 -0.0454 0 0 0 0 -0.0392 0.0191 1.0031 0.0036 0.0031 0.0079 0 0 0 -0.0422 0.0199 -0.0101 -0.9988 0.0423 -0.0310 -0.0451 0 0 0 0 -0.0417 0.0193 1.0018 0.0018 0.0055 0.0103 0 0 0 -0.0406 0.0209 -0.0098 -0.9989 0.0423 -0.0310 -0.0453 0 0 0 0 -0.0442 0.0200 1.0022 0.0023 0.0059 0.0086 0 0 0 -0.0389 0.0220 -0.0096 -0.9989 0.0423 -0.0311 -0.0454 0 0 0 0 -0.0456 0.0183 1.0029 0.0022 0.0048 0.0077 0 0 0 -0.0371 0.0231 -0.0094 -0.9989 0.0423 -0.0312 -0.0451 0 0 0 0 -0.0473 0.0178 1.0024 0.0023 0.0054 0.0099 0 0 0 -0.0354 0.0242 -0.0091 -0.9990 0.0424 -0.0311 -0.0451 0 0 0 0 -0.0497 0.0182 1.0028 0.0017 0.0071 0.0093 0 0 0 -0.0336 0.0252 -0.0089 -0.9990 0.0424 -0.0313 -0.0452 0 0 0 0 -0.0506 0.0181 1.0031 0.0050 0.0037 0.0080 0 0 0 -0.0321 0.0261 -0.0086 -0.9991 0.0423 -0.0314 -0.0453 0 0 0 0 -0.0524 0.0157 1.0037 0.0035 0.0035 0.0067 0 0 0 -0.0308 0.0269 -0.0085 -0.9991 0.0424 -0.0312 -0.0452 0 0 0 0 -0.0533 0.0188 1.0031 0.0042 0.0025 0.0071 0 0 0 -0.0298 0.0276 -0.0083 -0.9991 0.0423 -0.0314 -0.0451 0 0 0 0

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by