How to read a text file ?
古いコメントを表示
I have some (long)text files like this:
1996-002:16.39.23.565 67.060
1996-046:16.42.38.868 67.060
1996-057:17.08.58.620 67.060
1996-080:16.30.06.334 67.060
I want my script to read the first column and the two first numer. It is 1996 which is the year and 002 which is the day of the year. Someone know how to do this? I have tried with:
tmp = textscan(tline, '%s', 'delimiter', ' ', 'MultipleDelimsAsOne', 1);
But i get an error like: Subscripted assignment dimension mismatch. Anyone know what to do?
Thank you.
回答 (1 件)
KL
2017 年 5 月 12 日
fileID = fopen('YourFileName.txt');
C = textscan(fileID,'%d-%d:%s %s');
fclose(fileID);
7 件のコメント
kk1991
2017 年 5 月 12 日
KL
2017 年 5 月 12 日
then attach an example of your txt file. I tested with the data you gave and it works for me.
kk1991
2017 年 5 月 12 日
kk1991
2017 年 5 月 12 日
what exactly are you trying to do?
If your file name is myfile.txt,
>> fileID = fopen('myfile.txt');
C = textscan(fileID,'%d-%d:%s %d');
fclose(fileID);
whos C
Name Size Bytes Class Attributes
C 1x4 1040 cell
>> C{1}
ans =
1996
1996
1996
1996
kk1991
2017 年 5 月 12 日
KL
2017 年 5 月 12 日
attach the txt file here with few rows of data
カテゴリ
ヘルプ センター および File Exchange で Low-Level File I/O についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!