how to read a text file with numbers and strings

조회 수: 2 (최근 30일)
selassie ngara
selassie ngara 2016년 1월 19일
편집: Stephen23 2016년 1월 19일
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에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by