フィルターのクリア

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 Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by