import data from txt file with strings
5 ビュー (過去 30 日間)
古いコメントを表示
%I have a txt file contains both double and string characters.
% a.txt=
1 100 150
2 110 130
p.2 122 144 %for example
%I wanna retrieve all data from this txt file, I use importdata(a) then only doubles can be read.
v=importdata(a)
v=
1 100 150
2 110 130
%p.2 doesn't look in v. How can I retrieve all data from txt file?
0 件のコメント
採用された回答
dpb
2014 年 2 月 14 日
Use textscan instead; it can deal with non-regular data (with help from the formatting strings passed). It will return cell arrays for the fields which can include various data types. NB, however, that a more-or-less random mixture of text and numeric values can be very difficult to parse unless there is a pattern that you can exploit. At the worst, you may have to read the file as character line-by-line ( fgetl) and parse each field.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!