フィルターのクリア

Text file help.

1 回表示 (過去 30 日間)
Jason
Jason 2011 年 3 月 28 日
How can I delete the end of the table to the end of the text file. Also how can I pull out the last number, in this case 91?
@89 A 0.009 0.988 0.004 0.004
@90 B 0.002 0.002 0.991 0.003
@91 C 0.002 0.003 0.004 0.989
Next line of text
erwerwerwererwerwer
ewrwerwerwerwe
werwerewrwe
werwerwerwe
werwerwer

採用された回答

Jan
Jan 2011 年 3 月 28 日
FID = fopen(FileName, 'r');
if FID == -1; error('Cannot read file'); end
Data = textscan(FID, '%s', 'delimiter', '\n', 'whitespace', '');
fclose(FID);
CStr = Data{1};
startWith_at = strncmp(CStr, '@', 1);
last_at = find(startWith_at, 1, 'last');
last_number = sscanf(CStr{last_at}, '@%d');
% Delete trailing lines:
CStr(last_at + 1:end) = [];
Do you want to write the file afterwards?
FID = fopen(FileName, 'w');
if FID == -1; error('Cannot read file'); end
fprintf(FID, '%s\n', CStr{:});
fclose(FID);

その他の回答 (1 件)

A
A 2011 年 3 月 28 日
read file line by line with tab separator; check for @ character; ignore or delete all strings that do not start with @.
hope it works

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by