how to read a text file with numbers and strings

1 次查看(过去 30 天)
Hi
so i have a textfile that has numbers and strings as shown below:
1 74 8.00 50.27 0.20 0.97 0.50 7.76 0.42 8.55 BM_1587 SDE53 EXP003/60P -2.486e-001 no
2 -54 7.00 38.48 0.20 0.96 0.61 8.16 0.55 8.54 BM_1588 SDE53 EXP003/60P -2.357e-001 no
and i want to read it and use a for loop to see if any of the numbers don't match a certain number in the 11th column of the text file because ultimately i am trying to make the program skip the folders it had already read and calculated. the code is:
fileID = fopen('newfiles.txt','a+');% opens the text file
L= importdata('newfiles.txt','\t')% gives me the rows in the text file
bee= numel(L) %gives the actual number of rows
file = textread(fileID, '%4.0f\t %4.0f\t %4.2f\t %4.2f\t %4.2f\t %4.2f\t %4.2f\t %4.2f\t %4.2f\t %4.2f\t %s\t %s\t %s\t %4.3d\t','\t','\n')%trying to read the text file
for j=1:L
if x==file(j,11)
re_pit= 10;
continue
else
re_pit= 20;
end
end
if re_pit==10
continue
end
fclose(fileID);
  1 个评论
Stephen23
Stephen23 2016-1-19
编辑:Stephen23 2016-1-19
It would probably be much faster and neater to read the whole file into MATLAB, and perform the comparison all at once. Doing this in a loop is going to be much slower.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by